Re: Assigning pattern matches to an array
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 13:30:48 -0500
"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
.
- Follow-Ups:
- Re: Assigning pattern matches to an array
- From: Graham Stow
- Re: Assigning pattern matches to an array
- References:
- Assigning pattern matches to an array
- From: Graham Stow
- Re: Assigning pattern matches to an array
- From: John W. Krahn
- Assigning pattern matches to an array
- Prev by Date: Re: Assigning pattern matches to an array
- Next by Date: Re: Assigning pattern matches to an array
- Previous by thread: Re: Assigning pattern matches to an array
- Next by thread: Re: Assigning pattern matches to an array
- Index(es):