in reply to Fetching unique info

The code you show does not do what you think it does. It's declaring a new variable, $number, and then matching the regex against it. Obviously, the regex won't match against an empty string.

I think this code does what you meant to do:

my $got = q!<A HREF="JavaScript:AFunction('AA', 'B','0','Project','113 +')">San Francisco (Manager)!; $got =~ /'(\d{3})'\)">San Francisco \(Manager\)/; my $number = $1; print $number;

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Fetching unique info
by Anonymous Monk on Jun 05, 2003 at 14:34 UTC
    Thanks, But the problem is the number 113 changes and that is the number I am trying to print. Whatever the new number that replaced 113 is the number I am trying to fetch and print. I tried this and it doesnt work:
    my $got = q!<A HREF="JavaScript:AFunction('AA', 'B','0','Project','(\d +{3}')">San Francisco (Manager)!; print $got;
      What about something like this, assuming all of the lines will follow the same pattern. Given file lines such as:
      <A HREF="blah('aa','b','0','Project','112)"> Some Label Without Any Digits
      Do:
      open(F,"file.html"); @array = <F>; close (F); foreach (@array) { if (/\d/) { my ($s1,$s2,$s3,$s4,$needednumber) = split(/,/); $needednumber =~ s/[^\d]//g; print $needednumber . "\n"; } }