[sf-perl] qr{} question

Shlomi Fish shlomif at iglu.org.il
Tue May 26 12:24:16 PDT 2009


On Tuesday 26 May 2009 21:52:20 David Alban wrote:
> greetings,
>
> i'm trying to interpolate a value in a compiled regex.  it's
> interpolating the first time, but not the second.  that is:
>
>     #!/usr/bin/perl
>
>     use strict;
>     use warnings;
>
>     use Data::Dumper;
>     use Readonly;
>
>     Readonly my $FOO => 'foo';
>     Readonly my $FOO_REGEX => qr{ $FOO [^#]+ -D $FOO }xms;
>
>     print "\nReadonly:\n";
>     print '$FOO:       ', Dumper $FOO;
>     print '$FOO_REGEX: ', Dumper $FOO_REGEX;
>
>     my $BAR = 'bar';
>     my $BAR_REGEX = qr{ $BAR [^#]+ -D $BAR }xms;
>
>     print "\nNOT Readonly:\n";
>     print '$BAR:       ', Dumper $BAR;
>     print '$BAR_REGEX: ', Dumper $BAR_REGEX;
>
> prints:
>
>     Readonly:
>     $FOO:       $VAR1 = 'foo';
>     $FOO_REGEX: $VAR1 = qr/(?msx-i: foo [^#]+ -D $FOO
>     )/;
>
>     NOT Readonly:
>     $BAR:       $VAR1 = 'bar';
>     $BAR_REGEX: $VAR1 = qr/(?msx-i: bar [^#]+ -D $BAR
>     )/;
>
>
> i added the 'NOT Readonly' section 'cause i thought maybe that had
> something to do with using Readonly.  appears not to.  what am i
> missing.  why does it interpolate the first occurrence of the
> variable, but not the second?  i readlly don't wan't to hardcode the
> variable in the regex.
>

That appears to be a bug in perl. (tested on perl-base-5.10.0-25mdv2009.1 ). 
I'm CCing this to the perl5-porters. Nice catch!

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Rethinking CPAN - 

God gave us two eyes and ten fingers so we will type five times as much as we
read.




More information about the SanFrancisco-pm mailing list