in reply to Problems with LWP and REGEX
OK, I think I can help you with your problems 1 & 2, but I don't know anything about 3.
Your first question is about matching multiple times on multiple lines in one string, right? Your question would apply to data in the form of:
FOO=1 FOO=2 FOO=3
right?
#! /usr/bin/perl -w use strict; my $string = "FOO=1\nFOO=2\nFOO=3\n"; my @list; while ($string =~ /^FOO=(\d)/mg) { push (@list,$1); } print join(",",@list)."\n"; # prints out 1,2,3
Note the 'mg' at the end of the regex. The 'm' means you're dealing with multiline strings, and the 'g' means global matching.
Does that answer question number 1?
You're scanning the html code block for the pound and dollar values, right? I don't know if this is the right way to do this, but I usually do this kind of thing like this.
Assuming all dollar values are prefixed by $ and pound values are not and that there aren't any other numbers that look kindof like money in there.
my $dollars = 0; my $pounds = 0; while(<FILE>) { if (/>(\d+\.\d{2})<) { # no dollar sign, must be pounds $pounds = $1 } elsif (/>\$(\d+\.\d{2}) { # it's got a dollar sign, must be a dollar $dollars = $1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problems with LWP and REGEX
by sugarkannan (Novice) on Nov 19, 2005 at 02:30 UTC |