in reply to URL's

Why an array? I'm not aware of any way to apply a regex to an array as a whole (as opposed to iterating over each element and applying the regex individually).

If you're determined to do it, though, use LWP::Simple to get the web page and use split with some value to break up the scalar into a list, assigning it to your array. (I still think you might as well use the regex on the scalar and skip the array part.)

Replies are listed 'Best First'.
RE: Re: URL's
by Anonymous Monk on Mar 27, 2000 at 10:10 UTC
    Okay, let me rephrase.

    I have a URL whose source contains a stock price. It always comes after the only "last:" in the entire page. How can I tell perl to print whatever comes after that?

    nascent

      Note that btrott's solution will assign an empty string to $source if the pattern doesn't match. You will need to test for that at some time. I prefer a regex like this:
      my $quote = ""; if ($source =~ /last: ([0-9.]+)/i;) { $quote = $1; } else { # do the Not Found Dance }
      It's a matter of personal preference -- just don't neglect the check! Note also that the regex may run faster without the .* at the start (backtracking can be expensive).
      Try something like:
      my($quote) = $source =~ /.*last: ([0-9.]+)/i;
      where $source contains the source of the HTML page. You may need to tweak this a bit to match exactly what you want (for example, you want to match what comes after "last: "-- but how much do you want to match after that? The quote, which should, I guess, be a number?)