I've got a bit of a weird problem here. Basically, I'm trying to grab the contents of a page (in the below example, its google.com). I then try to find ALL of the words in the $RULES variable. The problem is, that its only matching 2 of the words (job and help). The code is;
--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html \n\n";
my @RULES = qw(job help tools);
use LWP::Simple;
my $html = get(" $html =~ s/\n//g;
if ($html =~ /tools/sig) { print "yay!"; } else { print "damn"; }
# do counting of rules...needed later.
my $c_rules_cnt = $#RULES; # get the number of entries..
# now we have the count, lets do some checkingto see if we have all
# the required words...if not, then we need to skip this URL, and pass
# back false value, so we can report that it wasn't added...
my $count = 0;
foreach (@RULES) {
$_ =~ s/[\t\n]/g/;
print "Word: $_ <BR>";
if ($html =~ /$_/sig) {
$count++;
print "<font color=blue>Match good word.. $_ </font><BR>";
}
} # end 'foreach' for @c_rules
# if we didn't get *ALL* the rules, then we need to skip this one...
if ($count == $c_rules_cnt) { print "<BR>Bad...<BR>"; } else { print "<BR>Good..<BR>"; }
--------------------------------------------------------------------------------
If I add something like this;
--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------
if ($html =~ /tools/i) { print "yay!"; } else { print "damn"; }
--------------------------------------------------------------------------------
...it shows "yay!" fine. Can anyone see why my code would do this? Is it a problem with my code, or a problem with the method I'm using?
Any ideas?
Cheers
Andy
--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html \n\n";
my @RULES = qw(job help tools);
use LWP::Simple;
my $html = get(" $html =~ s/\n//g;
if ($html =~ /tools/sig) { print "yay!"; } else { print "damn"; }
# do counting of rules...needed later.
my $c_rules_cnt = $#RULES; # get the number of entries..
# now we have the count, lets do some checkingto see if we have all
# the required words...if not, then we need to skip this URL, and pass
# back false value, so we can report that it wasn't added...
my $count = 0;
foreach (@RULES) {
$_ =~ s/[\t\n]/g/;
print "Word: $_ <BR>";
if ($html =~ /$_/sig) {
$count++;
print "<font color=blue>Match good word.. $_ </font><BR>";
}
} # end 'foreach' for @c_rules
# if we didn't get *ALL* the rules, then we need to skip this one...
if ($count == $c_rules_cnt) { print "<BR>Bad...<BR>"; } else { print "<BR>Good..<BR>"; }
--------------------------------------------------------------------------------
If I add something like this;
--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------
if ($html =~ /tools/i) { print "yay!"; } else { print "damn"; }
--------------------------------------------------------------------------------
...it shows "yay!" fine. Can anyone see why my code would do this? Is it a problem with my code, or a problem with the method I'm using?
Any ideas?
Cheers
Andy