[tpm] regex problem

Madison Kelly linux at alteeve.com
Fri Jul 3 11:47:11 PDT 2009


   Could someone riddle me why this isn't working?

#----------------------
#!/usr/bin/perl

use strict;
use warnings;

my $search_word="*4766";
my $joined_string="905-555-4766#:#jane die#:##:#1#:#18#:#2009-06-14 
13:44:33.617008#:#";
my $match=0;

if ($search_word=~/^\*(.*?)\*$/)
{
	# Match anywhere.
	my $local_search_word=$1;
	print __LINE__.": local_search_word: [$local_search_word]\n";
	$match++ if $joined_string =~ /$local_search_word/;
}
elsif ($search_word=~/^\*(.*?)/)
{
	# Match the end of the strings.
	my $local_search_word=$1;
	print __LINE__.": local_search_word: [$local_search_word]\n";
	$match++ if $joined_string =~ /$local_search_word#:#/;
}
elsif ($search_word=~/(.*?)\*$/)
{
	# Match the start of the strings.
	my $local_search_word=$1;
	print __LINE__.": local_search_word: [$local_search_word]\n";
	$match++ if $joined_string =~ /#:#$local_search_word/;
}
else
{
	# Match the strings exactly.
	$match++ if $joined_string =~ /#:#$search_word#:#/;
}

exit;
#----------------------

   When I run, I see that the second conditional matches because if '22: 
' being printed, but the $1 seems to be empty. According to 'perldoc 
perlre' I seem to be doing it right... Results say otherwise though. :)

Thanks!

Madi


More information about the toronto-pm mailing list