in reply to Re: URL's
in thread URL's

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

Replies are listed 'Best First'.
RE: RE: Re: URL's
by chromatic (Archbishop) on Mar 27, 2000 at 21:50 UTC
    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).
RE: Re: URL's
by btrott (Parson) on Mar 27, 2000 at 10:51 UTC
    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?)