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

Re^2: Pop/shift/delete on array

by revdiablo (Prior)
on Jul 14, 2005 at 16:39 UTC ( #474954=note: print w/replies, xml ) Need Help??

in reply to Re: Pop/shift/delete on array
in thread Pop/shift/delete on array

on an array it only undefines the value of an element

Actually, it does a bit more than "only" undefining the value. I'm not sure how useful this behavior is, but it's not quite the same as simply setting the value to undef. Here's a code snippet that demonstrates:

$ perl -MData::Dumper -le ' @array = (1 .. 3); delete $array[1]; print Dumper \@array; delete $array[2]; print Dumper \@array;'

When run, it outputs the following:

$VAR1 = [ 1, undef, 3 ]; $VAR1 = [ 1 ];

We see that the first delete call does indeed appear to simply set the value to undef, but when we delete again, it demonstrates the difference.

Update: betterworld beat me to it, by a pretty large margin. That'll teach me not to reload before replying. :-)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2020-09-26 15:33 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (141 votes). Check out past polls.