in reply to If statement in Foreach loop

Couple things. The first thing you should do is print $content to make sure it contains what you think it contains.

Second, you should quote $company in your regex. Like so..

if ($content =~/\Q$company\E/is){
That makes sure that it looks at what's in $company as all text. If you just put $company there, if there are any special characters, it will treat them as those special characters.

Hope this helps..
Rich

Replies are listed 'Best First'.
Re (tilly) 2: If statement in Foreach loop
by tilly (Archbishop) on Aug 18, 2001 at 21:15 UTC
    A followup on checking whether $content doesn't have what you think it does. A very common and easy way to make that mistake to make is to have a typo in a variable name. This can be very difficult to spot since your logic looks absolutely correct. (Your eye tends to fill in what it expects to see, so you skip over the typo again and again.)

    However using strict.pm will catch the vast majority of these errors. Which is why it is good to be in the habit of writing strict-compliant code and then to use strict. For instance in this case:

    foreach my $company (@companies) { # yada, yada }