Difference between revisions of "Open perl"
From Teknologisk videncenter
m (New page: == Piping from Perl to system commands == === Getting STDOUT from commands === <source lang=perl> #!/usr/bin/env perl print "Jeg er et perl program\n"; open FH,"ls -l|"; foreach my $i (...) |
m (→Getting STDOUT from commands) |
||
Line 1: | Line 1: | ||
== Piping from Perl to system commands == | == Piping from Perl to system commands == | ||
− | + | == Getting STDOUT from commands == | |
+ | === Metode 1 === | ||
<source lang=perl> | <source lang=perl> | ||
#!/usr/bin/env perl | #!/usr/bin/env perl | ||
Line 10: | Line 11: | ||
foreach my $i (<FH>) { | foreach my $i (<FH>) { | ||
print "Har modtaget linien: $i"; | print "Har modtaget linien: $i"; | ||
+ | } | ||
+ | </source> | ||
+ | === Metode 2 === | ||
+ | <source lang=perl> | ||
+ | #!/usr/bin/perl | ||
+ | |||
+ | my @files = `ls -l`; | ||
+ | |||
+ | for my $i (@files) { | ||
+ | print "Der er $i\n"; | ||
} | } | ||
</source> | </source> | ||
[[Category:Perl]] | [[Category:Perl]] |
Revision as of 04:28, 21 November 2009
Contents
Piping from Perl to system commands
Getting STDOUT from commands
Metode 1
#!/usr/bin/env perl
print "Jeg er et perl program\n";
open FH,"ls -l|";
foreach my $i (<FH>) {
print "Har modtaget linien: $i";
}
Metode 2
#!/usr/bin/perl
my @files = `ls -l`;
for my $i (@files) {
print "Der er $i\n";
}