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

Re: Use of shift in Ternary Operator

by hipowls (Curate)
on Mar 22, 2008 at 23:00 UTC ( #675692=note: print w/ replies, xml ) Need Help??


in reply to Use of shift in Ternary Operator

The problem is that ? is ambiguous, is it part of a ternery operator or the start of a ?? match? From Perl Regular Expressions Reference

?pattern? is like m/pattern/ but matches only once. No alternate delimiters can be used. Must be reset with reset().
puting () after shift resolves the ambiguity.

Update:To explain further, shift expects a single argument which is an expression that evaluates to an array. If no argument is provided it defaults to @_. When perl sees shift ? it doesn't know if you mean

shift(@_) ? 1: 2;
or something like
shift ?pattern? ? @a: @b;
the parentheses forces the first interpretation and shift defaults to using @_.


Comment on Re: Use of shift in Ternary Operator
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-09-20 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls