Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^2: Avoiding vivification with array slice

by jbert (Priest)
on Sep 09, 2008 at 14:45 UTC ( #710104=note: print w/replies, xml ) Need Help??

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

Cool. Accessing $a[$i] isn't enough to vivify (otherwise your defined test would do it).

So we don't actually need the defined test in your map and can get away with:

# This *doesn't* vivify $a[3,4,5] @b = map { $a[$_] } (0..5);


Replies are listed 'Best First'.
Re^3: Avoiding vivification with array slice
by ikegami (Pope) on Sep 09, 2008 at 19:45 UTC
    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://710104]
Discipulus yaaawn..
[Corion]: DST does that to everybody...
Corion attempts to find who to address to better target his drive-by patches
[Corion]: This time it's for the Duktape embedded Javascript engine, which would be nice to have IMO, but doesn't compile on Windows currently
[Corion]: I imagine it would be fun to have WWW::Mechanize:: Duktape, but I haven't seen a web browser written in Javascript yet, except the ones distributed with PhantomJs

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2017-03-27 11:03 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (319 votes). Check out past polls.