in reply to Re: Regular Expression tricky newline problem
in thread Regular Expression tricky newline problem
Careful, you’re invoking grep in scalar context. $keeper will only contain the count of matches. This has to be written with a parenthesised my, like so:
my ( $keeper ) = grep /^Line 3 : /, @lines;
However, that always goes through the entire data, regardless of where the match is found. A better way would be List::Util’s first; with which the context does not matter either:
use List::Util qw( first ); my $keeper = first { /^Line 3 : / } @lines;
Makeshifts last the longest.
|
---|