Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Can you use a scaler as an operator?

by hippo (Bishop)
on Jan 22, 2014 at 10:04 UTC ( [id://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.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found