I have the following Perl code:
my $progName = shift ;
open(IPLAYERLIST, "iplayer-list.html") or die "Cannot open iplayer index file iplayer-list.html\n" ;
while (<IPLAYERLIST>) {
if ( /($progName)/is ) {
#if ( /Just A Minute/is ) { <-- This works!
my $iplayerID = $1 ;
print "IPlayer program id for $progName is $iplayerID\n" ;
# === do stuff here ===
}
else
{
print "Failed to match $progName in $_\n";
}
}
IPLAYERLIST is a BBC IPlayer listing so it is searching for a specific program name.
If I call this with $progName = "Just A Minute", it fails to match, even though the string is in the file. If I call it with a single character, eg "M" then it succeeds. If I replace the $progName variable with a constant string ("Just A Minute") then it succeeds. When it prints $progName it always prints the correct string so I can't see how the regexp could be getting anything different.
I have cut the code and pasted it into a test script:
#!/usr/bin/perl
use strict ;
my $searchstr = "foo bar Just A Minute baz boo" ;
my $progName = $ARGV[0] ;
print "searching for [$progName] in [$searchstr]\n" ;
if ( $searchstr =~ /$progName/is ) {
print "Well the test worked\n" ;
} else {
print "Failed to match [$progName] in [$searchstr]\n";
}
and that works fine. So why does the first example not find "Just A Minute" in a file containing "Just A Minute"?!?!?
--- Alistair.