Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^2: push to a referenced array

by biga (Sexton)
on Sep 28, 2008 at 07:09 UTC ( #714133=note: print w/replies, xml ) Need Help??

in reply to Re: push to a referenced array
in thread push to a referenced array

Looks like the only benefit of this function is that you can omit surrounding @{}, which makes code cleaner. You may also add a ref check to this function for debug purposes.

Replies are listed 'Best First'.
Re^3: push to a referenced array
by jasonk (Parson) on Sep 28, 2008 at 14:15 UTC

    Hiding implentation details by writing tiny functions instead of just using references the way everybody else does rarely makes code cleaner. This is doubly true when the function you replace it with is obfuscated.

    If you really need a golf function to do it though, it can be made shorter...

    sub ref_push{push@{$_[0]||=[]},@_[1..$#_]}
    We're not surrounded, we're in a target-rich environment!
      Thank you for advice, guys. You've helped me a lot. %)
Re^3: push to a referenced array
by moritz (Cardinal) on Sep 28, 2008 at 09:00 UTC
    ... but you have to write a wrapper for every built-in list function.

    To me it feels more like this function would be used by people not confident with references and autovivification, in which case I recommend reading perldata and perlreftut instead of writing wrappers.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2022-05-23 05:14 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (81 votes). Check out past polls.