w*s 发帖数: 7227 | 1 my @cmd = `some cmds generate multiple lines of output`;
if($_ =~ /pattern/)
{
@var = split(/ /, $_);
foreach (@var)
{
print $_."\n"; # print all var in this line
}
}
my question is, if you look at the last $_,
can it work ? | j*a 发帖数: 14423 | 2 你没机器测试?
【在 w*s 的大作中提到】 : my @cmd = `some cmds generate multiple lines of output`; : if($_ =~ /pattern/) : { : @var = split(/ /, $_); : foreach (@var) : { : print $_."\n"; # print all var in this line : } : } : my question is, if you look at the last $_,
| G*******s 发帖数: 4956 | 3 写代码的人是猪头么?
【在 w*s 的大作中提到】 : my @cmd = `some cmds generate multiple lines of output`; : if($_ =~ /pattern/) : { : @var = split(/ /, $_); : foreach (@var) : { : print $_."\n"; # print all var in this line : } : } : my question is, if you look at the last $_,
| j*a 发帖数: 14423 | 4 :/tmp$ cat a.pl
$_ = "a b c d ef gh ij";
@var = split(/ /, $_);
foreach (@var)
{
print $_."\n"; # print all var in this line
}
:/tmp$ perl a.pl
a
b
c
d
ef
gh
ij
【在 w*s 的大作中提到】 : my @cmd = `some cmds generate multiple lines of output`; : if($_ =~ /pattern/) : { : @var = split(/ /, $_); : foreach (@var) : { : print $_."\n"; # print all var in this line : } : } : my question is, if you look at the last $_,
| w*s 发帖数: 7227 | 5 i simplified the non-working code and posted it here,
didn't test this one.
will debug tomorrow, thanks a lot!
【在 j*a 的大作中提到】 : :/tmp$ cat a.pl : $_ = "a b c d ef gh ij"; : @var = split(/ /, $_); : foreach (@var) : { : print $_."\n"; # print all var in this line : } : :/tmp$ perl a.pl : a : b
| L*1 发帖数: 11537 | 6 Be careful with ` character, my friend. Try the follow code and you will
know what I meant.
my @output = `ls -l`;
print @output;
【在 w*s 的大作中提到】 : my @cmd = `some cmds generate multiple lines of output`; : if($_ =~ /pattern/) : { : @var = split(/ /, $_); : foreach (@var) : { : print $_."\n"; # print all var in this line : } : } : my question is, if you look at the last $_,
|
|