in reply to Pop/shift/delete on array
let's say you have an array that looks like this
my @vals = ( 'cat', 'dog', 'mouse' );
Let's push onto this array:
outputs cat,dog,mouse,tiger.push( @vals, 'tiger' ); print( join(',',@vals ) );
Let's pop from this array:
outputs tiger.print( pop( @vals ) );
Let's shift from this array:
outputs cat.print( shift( @vals ) );
Note that both shift and pop remove the value from the array that you obtained:
prints dog,mouse.print( join(',',@vals ) );
Finally delete isn't an array function, it's used for deleting a hash element... update: whoops Limbic~Region has pointed out I was wrong about the delete function.. read his comments below.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Pop/shift/delete on array
by Limbic~Region (Chancellor) on Jul 14, 2005 at 12:34 UTC |
In Section
Seekers of Perl Wisdom