hey all,
Scratchin' my head on this one for a couple of hours now, looking at camels. sheep and other documentation creatures to no avail. I'm trying to match a pattern that's already (must be) in a variable like so:
$var = "coyote"; while (<FILE>) { if ($_ =~ /$var/i) { print $_ . " matches\n"; }; };
great - this works until I come to
$var = "Wile E. Coyote";
and fails to match. Is there a way to do this?
It's not clear to me whether the string "Wile E. Coyote" is in the input file, or is assigned to $var. If it's in the input file, it works for me (see below, where I use the trick of a __DATA__ section so I don't need a separate input file for testing.
If, however, you're assigning the string "Wile E. Coyote" to $var, then trying to match strings read from an input file, then I'd need an example of an input line it's failing to match properly. Keep in mind, though, that the period after the E will be treated as a regular expression wildcard - i.e. it'll match any single character in that position. E.g. it will match "Wile EX Coyote".
$var = "coyote"; while (<DATA>) { if ($_ =~ /$var/i) { print $_ . " matches\n"; }; };
__DATA__ Something else coyote Wile E. Coyote
John Deighan Public Consulting Group 1700 Kraft Dr. Suite 2250 Blacksburg, VA 24060 [EMAIL PROTECTED] 540-953-2330 x12 FAX: 540-953-2335
_______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs