Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Avoiding vivification with array slice

by ikegami (Patriarch)
on Sep 09, 2008 at 19:45 UTC ( [id://710184]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Avoiding vivification with array slice
in thread Avoiding vivification with array slice

The point of the defined wasn't to prevent autovivification, but to implement the grep you had in your original code. The following two snippets are equivalent.
@b = map { defined($a[$_]) ? ($a[$_]) : () } 0..5;
@b = grep { defined } map { $a[$_] } 0..5;

What you suggested (@b = map { $a[$_] } 0..5;) is *not* equivalent.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2024-03-28 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found