[sf-perl] qr{} question

David Alban extasia at extasia.org
Tue May 26 11:52:20 PDT 2009


i'm trying to interpolate a value in a compiled regex.  it's
interpolating the first time, but not the second.  that is:


    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;


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

Live in a world of your own, but always welcome visitors.

More information about the SanFrancisco-pm mailing list