Hi,
Be aware of the subtle difference between:
perl -ne'/(data)/ && print $1 and last' file.txt
perl -ne'/(data)/ && print $1 && last' file.txt
Of course, I saw the subtle difference, and how you used
.. print ($1) ...
the parentheses which is effectively the same thing if "and" is used instead of "&&" check this: Using
perl -MO=Deparse -ne'/(data)/ && print $1 && last' file.txt
you gets:
LINE: while (defined($_ = <ARGV>)) {
print $1 && last if /(data)/;
}
but using
perl -MO=Deparse -ne'/(data)/ && print ($1) && last' file.txt
gives:
LINE: while (defined($_ = <ARGV>)) {
last if /(data)/ and print $1;
}
Which is same as this:
perl -MO=Deparse -ne'/(data)/ && print $1 and last' file.txt
LINE: while (defined($_ = <ARGV>)) {
last if /(data)/ and print $1;
}
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
|