in reply to pop an array
If you need to reverse the contents of the array and you don't want to use the reverse function, you could do something like this:
use strict; use warnings; my @foo = @ARGV; # get the array we're reversing # reverse it: my @tempfoo; while (scalar (@foo)) { my $element = pop (@foo); push @tempfoo, $element; } @foo = @tempfoo; # foo has been reversed...
There are probably a hundred different ways to do it if you want to do it just to do it. But stick with reverse unless you absolutely don't want to. It's much cleaner and easier to understand.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: pop an array
by Fletch (Bishop) on Feb 09, 2004 at 14:40 UTC | |
by Vautrin (Hermit) on Feb 09, 2004 at 14:46 UTC | |
| |
by ambrus (Abbot) on Feb 10, 2004 at 14:21 UTC |