cdherold has asked for the wisdom of the Perl Monks concerning the following question:
Using a foreach loop works fine, but when I try to put in a nested "if" statement the program doesn't seem to work.
I'm trying to screen throught the contents of a webpage to determine if a company is listed. If it is listed, I want to pull out the information starting at the company name ($company) until the tag </tr>.
I need to determine if the company is listed before doing the extraction.
The basic code without determining if the company is listed or not before extracting works fine.
This works ...
BUT when I try to put the if statement within the foreach loop, it doesn't seem to work.$content = get($url); @companies = ("AOL Time Warner", "Genetech","Broadwing"); foreach $company (@companies){ $content =~ /$company(.*?)<\/tr>/gsmi; $new_coverage = $1; print "$new_coverage <p>" }
This doesn't work ...
$content = get($url); @companies = ("AOL Time Warner", "Genetech","Broadwing"); foreach $company (@companies){ if ($content =~ /$company/gsmi){ $content =~ /$company(.*?)<\/tr>/gsmi; $new_coverage = $1; print "$new_coverage <p>"; } }
Any idea's on why this is happening?
thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach loop with nested
by John M. Dlugosz (Monsignor) on Aug 02, 2001 at 02:23 UTC | |
by cdherold (Monk) on Aug 02, 2001 at 08:09 UTC | |
|
Re: foreach loop with nested
by japhy (Canon) on Aug 02, 2001 at 01:37 UTC | |
|
Re: foreach loop with nested
by arturo (Vicar) on Aug 02, 2001 at 02:41 UTC | |
|
Re: foreach loop with nested
by runrig (Abbot) on Aug 02, 2001 at 03:55 UTC |