in reply to substring exists at particular postion?

You can use substr function for getting the substring in the positions you want and compare it to your string:
my $bigStr = 'Once upon a time there was a little programer'; my $littleStr = 'time'; my $neededPos = 12; my $length = 4; if (substr($bigStr, 12, $length) eq $neededStr) { &do_something; } else { &do_somthing_else; }


Thanks.

Hotshot

Replies are listed 'Best First'.
Re: Re: substring exists at particular postion?
by joealba (Hermit) on May 23, 2002 at 13:11 UTC
    What about this too (borrowing from hotshot's example):
    my $bigStr = 'Once upon a time there was a little programer'; my $littleStr = 'time'; if ($bigStr =~ /^(.*?)$littleStr/) { my $position = length($1); print "Found $littleStr at position $position\n"; # Do whatever depending on the position returned }
    Since you mentioned that you'd be looking for the string in more than one position, this will allow you to do the match once.