Re: Assigning pattern matches to an array
- From: "Graham Stow" <graham@xxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 18:42:01 -0000
"Uri Guttman" <uri@xxxxxxxxxxxxxxx> wrote in message
news:x7psa1kzhj.fsf@xxxxxxxxxxxxxxxxxxx
"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
Thanks Uri!
push(@matches, $line=~/\b\w+@\w+\b/g); did it for me
The pattern doesn't match an email address, but I can work on that...
Graham
.
- Follow-Ups:
- Re: Assigning pattern matches to an array
- From: DJ Stunks
- 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
- Re: Assigning pattern matches to an array
- From: Uri Guttman
- 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):