[Israel.pm] regex question

Shlomi Fish shlomif at iglu.org.il
Wed Jun 21 08:54:19 PDT 2006


On Wednesday 21 June 2006 15:39, Yossi.Itzkovich at ecitele.com wrote:
> Hi,
>
> I was asked by a friend:
>
> if ($a)
> {
>       m/$pattern/;
> }
> else
> {
>       m/$pattern/s;
> }
>
>
> Is there a way to write the regex line only once ? can I put the "s" option
> as a variable ?
>

You can do a:

my $pat = qr/[ Insert Pattern Here ]/;

return $a ? m/$pat/ : m/$pat/s.

Also look at the (?:s ... ) clustering in perldoc perlop or perldoc perlre.

Regards,

	Shlomi Fish

> Thanks
>
> Yossi
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

-- 

---------------------------------------------------------------------
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