in reply to Matching against $_ behaves differently than matching against a named scalar?
Now of course the regex could be written differently. This means the same thing.use strict; use warnings; while (<DATA>) { if ( (my $first,my $second) = /^([^ ]+) ([^ ]+)/ ) { print "$first $second\n"; } } #prints: hello one __DATA__ hello one two three kjsf kjsd kjd
use strict; use warnings; while (<DATA>) { if ( (my $first,my $second) = /^(\S+)\s+(\S+)/ ) #ok, allow an extra + spaces between tokens { print "$first $second\n"; } } #prints: hello one __DATA__ hello one two three kjsf kjsd kjd
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching against $_ behaves differently than matching against a named scalar?
by Anonymous Monk on Apr 23, 2020 at 02:23 UTC |