Code Comments
Programming Forum and web based access to our favorite programming groups.I need to take as variable 2 things a) The pattern to match b) Match settings like global, case insensitivity etc.. so i want to have a program like $str = "Japh" ; $pat = "JA" ; $key = "gi" ;#global match, case insensitive print "Voila!" if ($str =~ /$pat/$key); this errors with Scalar found where operator expected at test.pl Any alternatives ?
Post Follow-up to this messageMachoq wrote: > I need to take as variable 2 things > a) The pattern to match > b) Match settings like global, case insensitivity etc.. > > so i want to have a program like > > $str = "Japh" ; > $pat = "JA" ; > $key = "gi" ;#global match, case insensitive > print "Voila!" if ($str =~ /$pat/$key); > > this errors with Scalar found where operator expected at test.pl > Any alternatives ? Modifiers like i can be included in the pattern itself: my $key = 'i'; my $pat = "(?$key:JA)"; However using modifiers like g would require you to use eval(): print 'Voila!' if eval "$str =~ /$pat/$key"; John -- use Perl; program fulfillment
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.