| Michael Gale 2005-08-23, 6:56 pm |
| Hello,
I resolved my issue, I forgot that in the file it may contain a CR,
I used chomp to remove it.
Michael
-------- Original Message --------
Subject: Re: regex stored in variables ?
Date: Tue, 23 Aug 2005 14:16:22 -0600
From: Michael Gale <michael.gale@pason.com>
To: beginners@perl.org
References: <430B7790.4010608@pason.com>
<Pine.LNX.4.61.0508231535490.24982@perlmonk.org>
Ok,
I have tried your suggestion and it is working perfectly, but I want
to be able to load a variable from a file, so I am using the following
method to do so:
if ( -e "ConfigLoad.pm" ) {
use ConfigLoad;
$Config = new ConfigLoad();
} else {
&contact_func("ERROR: Could not find ConfigLoad.pm",1);
}
$Config->read($config_file) or die "Can't read config file $config_file";
Which has the following layout:
[section]
name=value
value will be my regex, so need to be able to do something like the
following (which I can not get to work)
my $exp_test=qr/$Config->get('section.name')/;
if ($string =~ $exp_test) { ....
I do not understand what I am missing / doing wrong ?
Thanks
Michael
Jeff 'japhy' Pinyan wrote:
> On Aug 23, Michael Gale said:
>
>
>
> That's got a couple problems with it, but I'm not going to get into them.
>
> To store a regex (not a pattern match, mind you, but a regex) in a
> variable, use the qr// constructor:
>
> my $exp_test = qr/^\d+$/;
>
> Then use it like so:
>
> if ($string =~ $exp_test) { ... }
>
> You can also embed that inside another regex:
>
> if ($string =~ /$exp_test/m) { ... }
>
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
|