what 's the issue?
chomp function can't assign to others variable.
for example:
# cat /tmp/a
a
d
g
f
# cat /tmp/b.pl
#!/usr/bin/perl
$file="/tmp/a";
@array=qw(a b c d);
open(FH,"$file") or die "couldn't open $file:$!";
foreach (<FH>) {
$line=chomp($_);
print "$line\n";
foreach (@array) {
$item=chomp($_);
if ("$item" eq "$line" ){
print "$line\n";
}
}
}
|
resulut:
1
1
1
1
what's the root cause?
#!/usr/bin/perl
$file="/tmp/a";
@array=qw(a b c d);
open(FH,"$file") or die "couldn't open $file:$!";
foreach (<FH>) {
chomp;
$line = $_;
foreach (@array) {
chomp;
$item=$_;
if ("$item" eq "$line" ){
print "$line\n";
}
}
}
|
note: The result of chomp can't assign to other variable
$line = chomp($_); #return value will be 1