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
In reply to specific /\G/g troubles by duelafn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |