Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

dynamic regex
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 ?

Report this thread to moderator Post Follow-up to this message
Old Post
Machoq
10-27-04 08:57 PM


Re: dynamic regex
Machoq 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

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
10-27-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:01 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.