Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Can you use a scaler as an operator?

by hippo (Vicar)
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 (Abbot) 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 wandering the Monastery: (14)
As of 2015-07-06 18:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (80 votes), past polls