in reply to Can you use a scaler as an operator?

You would need to use Extended Patterns to accomplish this I think. eg.

if ( 'asdf' =~ /(?$icase)$str/ ) { print "it works!\n" }

See the perlre document for full details.

Replies are listed 'Best First'.
Re^2: Can you use a scaler as an operator?
by AnomalousMonk (Archbishop) on Jan 23, 2014 at 00:12 UTC

    Rather than using a defined vs undefined value for the op variable, here's an example of that approach using  'i' vs either  '#' or  '' (empty string).

    >perl -wMstrict -le "my $s = 'ASdf'; ;; for my $op ('i', '#', '') { printf qq{for op eq '$op': }; print 'asdf' =~ m{ (?$op) \Q$s\E }xms ? '' : 'NO ', 'match'; } " for op eq 'i': match for op eq '#': NO match for op eq '': NO match

    Update:  '-i' also works for turning off (or not turning on) case-insensitive matching.

Re^2: Can you use a scaler as an operator?
by jar00n (Novice) on Jan 22, 2014 at 21:28 UTC
    Very cool, I haven't stumbled across that syntax yet. Thanks