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
In reply to foreach loop with nested by cdherold
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |