OK, I think I can help you with your problems 1 & 2, but I don't know anything about 3.

1

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?

2

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; } }

In reply to Re: Problems with LWP and REGEX by pileofrogs
in thread Problems with LWP and REGEX by sugarkannan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.