in reply to Re: Regex Grumblings (Variable Interpolation)
in thread Regex Grumblings (Variable Interpolation)

I'm probably missing the boat here, but the documentation claims that since "patterns are processed as double-quoted strings, the normal double-quoted interpolations will work."1
my $foo = "`ls`"; # "Evil" command my $bar = "$foo"; print $bar,"\n";
All you get is:     `ls` I wasn't hoping for a miracle to occur, just that $foo would be translated as literal string '$bar', and that the '$' would be recognized as just another ASCII character, not the end of line anchor. After all, if we're on the subject of evil, now this means that you can put all sorts of wacky stuff in your variable and it gets interpolated as regexp material, or at least jostles your program with a warning:
my $foo = '(?{die})'; s/$foo/XYZ/g; # Eval-group not allowed at runtime, use re 'eval'
Maybe there should be a switch for regexps which cause any interpolated strings to be interpreted as just text and any meaning is disregarded. Of course, you can always do this with \Q and \E...
1Programming Perl, 2nd Ed., pg. 60

Replies are listed 'Best First'.
Re: Re^2: Regex Grumblings (Variable Interpolation)
by chipmunk (Parson) on May 23, 2001 at 23:22 UTC
    if we're on the subject of evil, now this means that you can put all sorts of wacky stuff in your variable and it gets interpolated as regexp material,
    Um, that's not evil, that's intentional. How else would you store a regular expression in a variable for later use? (Remember that qr// is only a recent addition to Perl.)