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

Re: Avoiding vivification with array slice

by betterworld (Curate)
on Sep 09, 2008 at 12:57 UTC ( [id://710072]=note: print w/replies, xml ) Need Help??


in reply to Avoiding vivification with array slice

You could modify the line in question like this:

@b = grep { defined $_ } @{[ @a[0..5] ]};

Or even:

@b = grep { defined $_ } @{[@a]}[0..5];

But whatever approach you choose, make sure that you comment it so it's clear why you do it.

Replies are listed 'Best First'.
Re^2: Avoiding vivification with array slice
by jbert (Priest) on Sep 09, 2008 at 13:45 UTC

    Ah, this is cool. An anonymous copy, dereferenced on the spot.

    And, as you say, definitely comment-worthy.

    Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-24 18:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found