Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Array Plus Operator

by shmem (Chancellor)
on Dec 15, 2017 at 14:58 UTC ( #1205587=note: print w/replies, xml ) Need Help??


in reply to Array Plus Operator

There's no difference between these two lines

@{ $self->bar || +[] }; @{ $self->bar || [] };

since there is no ambiguity. [] returns a scalar - a reference to an anonymous, empty array - in either case. But the original author perhaps thought it was needed. AFAIK this doesn't behave different in any perl5.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Array Plus Operator
by SleepyJay (Beadle) on Dec 15, 2017 at 15:01 UTC

    That's what I assumed, but thanks for the sanity check! Odd looking legacy code gives me deep paranoia when changing it!

    The current theory in the office is that someone "fat-fingered" it... since the "+" and "[" are so close on the keyboard... otherwise... NFI

    Or maybe you could pass in a default to use if $self->bar was false... so it was originally @{ $self->bar || +shift } and then the code evolved and someone replaced the "shift" with "[]" and left the "+" around, JIC

      ... someone "fat-fingered" it... since the "+" and "[" are so close on + the keyboard...

      But "+" also requires a shift, so it would have to be a "hyper-caffeinated-fat-finger."


      Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1205587]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2018-01-21 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (227 votes). Check out past polls.

    Notices?