in reply to array pushing

Just to note, a filehandle would work because it can act as an array. That's why you can do @lines = <FH>;

Now, concerning $ARRAY[++$#ARRAY] = $value;. Array elements are accessed by $array[$index]. So to access the second element in the array @array you would write $array[1]. It is a one because array indexes start at 0. Now, the $#ARRAY syntax is a special way of saying @array - 1; basically, it returns the index of the last element in @ARRAY. The ++ increments this value and then uses it as the new index, which it sets equal to $value.

As for the other question, this should work... Hopefully it gives you an idea of how to do things. Read up on sort if you don't get that part.

while (($this, $that) = each(%list)) { push @array, $this, $that; } @array = sort { $a <=> $b } @array;

I hope that helps. You may also want to read the very helpful article "List" Is a Four-Letter Word.

Added part about the "list into array" thing.

Replies are listed 'Best First'.
Re: Re: array pushing
by chromatic (Archbishop) on Apr 25, 2003 at 23:31 UTC

    Actually, the filehandle example you give works not because "a filehandle can act as an array" but because readline returns a list of all lines that can still be read from the filehandle in list context. That is, an operator that works on filehandles has a nice shortcut to get a list of things in one fell swoop.

    Subtle difference, but this is Perl. :)