eh, is not possible to get the values in parens when you do a reg match on an
evaled string ?

Yes, it is.


consider the snippt below, how do i get the values into $1, $2 etc ...

It'd be easier to explain exactly what you are trying to do.


my $str = /(.{11})(.{10})/i;

This assigns the result of a regexp search of $_ to $str (probably true or false). Ie, it is equivalent to:


my $str = ($_ =~ /(.{11})(.{10})/i);

It seems unlikely this is what you intend.

my $line  = "test string etc  etc test string";
if ($line =~ eval("/" . $str . "/")) {
  print "id = $1\n";
  print "pw = $2\n";
}

I would presume you want something like this:


my $str  = '(?i)(.{11})(.{10})';
my $line  = "test string etc  etc test string";
if ($line =~ /$str/ ) {
  print "id = $1\n";
  print "pw = $2\n";
}

Note the use of the (?i) modifier to turn off case sensitivity inside the regexp. Note that it is needed since your regexp is case insensitive anyway.

Chckout:

perldoc perlre

for lost and lots of cool regexp stuff like (?i:regexp) to turn off case sensitivity in part of a search and (?:) to bracket without creating a $n entry and such. And then check out the zero length assertions for some even cooler stuff.

Enjoy,
   Peter.


-- <http://www.interarchy.com/> <http://download.interarchy.com/>

Reply via email to