[Israel.pm] use $a in match

Shlomi Fish shlomif at iglu.org.il
Tue Jun 13 06:12:11 PDT 2006


Hi!

Just a preliminary note: please don't start new topics by replying to an 
existing message. Instead, write a new message to perl at perl.org.il.

On Tuesday 13 June 2006 14:56, Ernst, Yehuda wrote:
> Hello
>
>
> Can i use $a parameter inside match
>
>
> instead of writing
>
> ($q) = $string =~ m/5/;
>
> I will write
>
> $a=5;
>
> ($q) = $string =~ m/$a/;
>

Try it and see.

Yes, you can. The regexp operators interpolate. Just note that the string $a 
will specify a little regular expression. So if you do:

$a = "b.*c";

It will match b followed by any number of characters followed by c. If you 
want to escape the special characters use \Q and \E:

$string =~ m{\Q$a\E};

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://www.shlomifish.org/

95% of the programmers consider 95% of the code they did not write, in the
bottom 5%.



More information about the Perl mailing list