in reply to How can I change substitution options within a program?

See perlop, namely qr/PATTERN/options. With qr// you can change imosx options as you wish within dynamically generated patterns.

Replies are listed 'Best First'.
Re^2: How do I change substitution options within a program?
by crashtest (Curate) on Oct 31, 2006 at 23:28 UTC

    See perlop, namely qr/PATTERN/options. With qr// you can change imosx options as you wish within dynamically generated patterns.
    I read your comment as meaning you can set the regex options from variables when using qr//. However, none of the following work for me:
    $mods = "im"; $test = qr/xyz/$mods; # Syntax error. $test = qr/xyz/"$mods"; # Ditto. $test = qr/xyz/\$mods; # Ditto. # ... out of ideas.

    Could you clarify your post? What can you do with qr// and modifiers that you can't with m// or s///?

      Nothing. Maybe he was thinking of the following:

      # XXX WRONG DON'T USE THIS $re = qr/$re/i if $opt{i}; $re = qr/$re/m if $opt{m}; $re = qr/$re/s if $opt{s}; $re = qr/$re/x if $opt{x};

      On the other hand, the following does work:

      $re = "(?i:$re)" if $opt{i}; $re = "(?m:$re)" if $opt{m}; $re = "(?s:$re)" if $opt{s}; $re = "(?x:$re)" if $opt{x};