[Israel.pm] use $a in match

Oded Arbel oded-linux at typo.co.il
Tue Jun 13 06:06:25 PDT 2006


On Tue, 2006-06-13 at 14:56 +0300, Ernst, Yehuda wrote:
> Can i use $a parameter inside match

Not without escaping it, as $ has a special meaning inside a regular
expression.

> I will write 
> 
> $a=5;
> 
> ($q) = $string =~ m/$a/;

A simple way to escape is to use \Q and \E, as thus:
$string =~ m/\Q$a\E/

--
Oded
::..
Conway's Law: /prov./
"If you have four groups working on a compiler, you'll get a 4-pass
compiler".
    -- The Jargon File





More information about the Perl mailing list