duelafn has asked for the wisdom of the Perl Monks concerning the following question:
Here are the results of a few test casesuse strict; use warnings; use LWP::UserAgent; print 'Enter Search: '; chomp( my $x = <STDIN> ); # Create a user agent object my $ua = new LWP::UserAgent; $ua->agent("AgentName/0.1 " . $ua->agent); # Create a request my $req = new HTTP::Request POST => 'http://www.usps.com/cgi-bin/zip4/ +ctystzip2'; $req->content_type('application/x-www-form-urlencoded'); $req->content('ctystzip='.$x); my $res = $ua->request($req); my @matches; my $data = $res->content; $data =~ /----------</g; if ($x =~ /^\s*\d{5}\s*/) { while ($data =~ /\G(br>((\w+\s)+\s*\w\w ))/ig) { push @matches, $2; } } else { while ($data =~ /\G(br>(\d{5}))/ig) { push @matches, $2; } } print 'Found ',$#matches+1,' matches:',"\n ", join("\n ", @matches), +"\n";
The tests tell me that what's wrong is in the "else" case, but when I put a "print pos $data" in there it prints a reasonable position.[duelafn@XYZZY bbdb]$ perl States.pl Enter Search: Mishawaka, IN Found 0 matches: [duelafn@XYZZY bbdb]$ perl States.pl Enter Search: Chicago, IL Found 0 matches: [duelafn@XYZZY bbdb]$ perl States.pl Enter Search: 84102 Found 1 matches: SALT LAKE CITY UT [duelafn@XYZZY bbdb]$ perl States.pl Enter Search: 12345 Found 1 matches: SCHENECTADY NY
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: specific /\G/g troubles
by chipmunk (Parson) on Dec 13, 2001 at 09:38 UTC | |
|
Re: specific /\G/g troubles
by dws (Chancellor) on Dec 13, 2001 at 10:45 UTC | |
|
Re: specific /\G/g troubles
by duelafn (Parson) on Dec 13, 2001 at 09:28 UTC | |
|
Re: specific /\G/g troubles
by Fastolfe (Vicar) on Dec 13, 2001 at 22:07 UTC |