Hi John,

Thanks for a very quick response John.

It gives the error as below:

Trailing \ in regex m/D:\STUDY\PERL\MYFTP\/ at D:\Study\Perl\MyFtp\Ftp1.pl line
109.

($base,$path,$type) = fileparse($ARGV[0]);
$pattern=$path;
print "matches" if $string =~ m/$pattern/;

I print $pattern and it is D:\STUDY\PERL\MYFTP\. You are probably right that
there are some meta-characters, \ :, that I need to escape, but how do I escape
them if they are variables? Basically, I actually just want to search for
whether I found a match of a particular string on $path and do not need to
assign it to $string, how do I do that? Am not sure if am doing it right
really, so in theory, I just want to do something like this ...

if ($path =~ m/$pattern/) {
  print 'match';
  ... do something here ...
} else {
  print 'no match';
  ... do something here ...
}

Or do I get the regex logic all wrong ...

The one liner is just a test on whether am using the pattern matching correctly
or not.

Also, how do I do a non-case sensitive match. At the moment, am using uc() to
upper case both the string and the pattern that I am searching for.


Quoting "John W. Krahn" <[EMAIL PROTECTED]>:

[EMAIL PROTECTED] wrote:
Hi all,

Hello,

Can some please advise how to get this to work?

   print "matches" if $string =~ m/$pattern/;

Am trying to search for a pattern but the pattern has to be a variable. Thanks
in advance.

How did this "not work"?  What is it not doing that you want it to do?  What
warning/error messages did it generate?

You probably have regex meta-characters in $pattern that need to be escaped.


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to