Difference between revisions of "Open perl"

From Teknologisk videncenter
Jump to: navigation, search
m (Getting STDOUT from commands)
m (Getting STDOUT from commands)
 
Line 2: Line 2:
 
== Getting STDOUT from commands ==
 
== Getting STDOUT from commands ==
 
=== Metode 1 ===
 
=== Metode 1 ===
 +
Læser linierne ind en efter en som de behandles
 
<source lang=perl>
 
<source lang=perl>
 
#!/usr/bin/env perl
 
#!/usr/bin/env perl
Line 14: Line 15:
 
</source>
 
</source>
 
=== Metode 2 ===
 
=== Metode 2 ===
 +
Henter alle linier før de behandles
 
<source lang=perl>
 
<source lang=perl>
 
#!/usr/bin/perl
 
#!/usr/bin/perl

Latest revision as of 04:37, 21 November 2009

Piping from Perl to system commands

Getting STDOUT from commands

Metode 1

Læser linierne ind en efter en som de behandles

#!/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

Henter alle linier før de behandles

#!/usr/bin/perl

my @files = `ls -l`;

for my $i (@files) {
 print "Der er $i\n";
}