Re: How to search/match a variable pattern
- From: benbart@xxxxxxxxxxxx
- Date: Sat, 12 Aug 2006 17:14:18 +1200
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" <krahnj@xxxxxxxxx>:
benbart@xxxxxxxxxxxx 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: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>
.
- References:
- How to search/match a variable pattern
- From: benbart
- Re: How to search/match a variable pattern
- From: John W. Krahn
- How to search/match a variable pattern
- Prev by Date: Re: How to search/match a variable pattern
- Next by Date: Re: Dynamic variables - from INI files ...
- Previous by thread: Re: How to search/match a variable pattern
- Next by thread: Re: How to search/match a variable pattern
- Index(es):
Relevant Pages
|