Good day;
See below for what I think may be the issues...Haven't tried it out before, 
but hope this helps.

At 09:23 AM 5/22/2001 -0400, Robin Lavallee (LMC) wrote:

>Hi people,
>
>         I need to match string against regular expressions that are only
>known at run-time. I'm having problems doing it so I made a small test
>script like the following :
>
>#!/net/tcmvega35/data1/automation/perl/bin/perl -w
>
>use strict;
>die "test.pl [string] [regex]" unless $#ARGV == 1;
>
>if ($ARGV[0] =~ $ARGV[1])
>{
>         print "$ARGV[0] matches $ARGV[1]\n";
>}
>else
>{
>         print "$ARGV[0] does not match $ARGV[1]\n";
>}
>
>On the command lines, the following happend
>
>allo al         => match
>allo /al/               => no match (should match, no ?)

No, because it's looking to match the literal (/). If the left hand value 
had (/), then it would match.

>allo lo$                => match
>allo ^al                => match
>allo ^ao$               => no match (should match, no ?)

No, see below.


>Questions :
>
>         - Why don't I need the regular expression delimiters (/), is it
>implicit when using
>variables ?

Apparently so. I've never used =~ with two arguments before. (There are 
some REGEXperts out there who may be able to help you more)

>         - If I don't add them (/), will it still work for all cases ?

I'm not sure, but it seems by your test cases that if you don't use (/) it 
should work for all cases.

>         - Why doesn't the last case work ?

It's looking for a string that begins with ao (^ao) and ends with ao (ao$). 
If your argument was ao, it should match (and I think ao<anything else 
here>ao would match as well).


>Thanks !
>
>-Robin

Reply via email to