On Feb 26, Balaji Thoguluva said:

>I have a question on pattern matching. Assume I have a line like this
>consisting of header field(via) and values(IPaddress) repeated like below
>
>via: 192.168.6.100; via:192.168.6.101; via: 203.290.89.90; ......so on
>
>I would like to know how many via: header field occur and to get each
>via header field value. I want to know how to loop through each via
>header field to extract the value by pattern matching expressions.

You want to use the /g modifier to your regex.  Either employ it in a
while loop like this:

  while ($string =~ m{via:\s*(\d+\.\d+\.\d+\.\d+)}g) {
    print "value = $1\n";
  }

or use it in list context like this:

  @values = $string =~ m{via:\s*(\d+\.\d+\.\d+\.\d+)}g;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to