Re: Assigning pattern matches to an array



"JWK" == John W Krahn <someone@xxxxxxxxxxx> writes:


JWK> That line is short for:

JWK> @matches = $_ =~ /\b\w+@\w+\b/g;

JWK> But the current line is in $line not in $_ so you have to do:

JWK> @matches = $line =~ /\b\w+@\w+\b/g;

and that will overwrite any matches for the previous line. so the print
loop will only see the matches on the last line of a file. push is
needed here. or a map can be used which will remove the loop:

@matches = map /\b\w+@\w+\b/g, @lines ;

if that is in a file loop, use push also.

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.