Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Can you use a scaler as an operator?

by hippo (Curate)
on Jan 22, 2014 at 10:04 UTC ( #1071579=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: Can you use a scaler as an operator?
Download Code
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
Re^2: Can you use a scaler as an operator?
by AnomalousMonk (Monsignor) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1071579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-09-03 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls