Re: Textfile to array or hash
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 27 Jul 2008 17:29:01 GMT
Bill H <bill@xxxxxxxxx> wrote:
I havent used push before, does it perform the same exact function as
using "="? So in you sexample:
push @artists, $data[ 2 ] if $data[ 0 ] > 50;
Would this be the exact equivalent of doing:
if ($data[0] > 50){$artists[@artists] = $data[2];}
Yes, here it does. It simply appends '$data[2]' to the end of
the '@artists' array. And it does it more efficiently (at
least that's what the documentation claims).
Or does more happen with push?
Well, you can also 'push' a whole list, thus appending a number
of new elements to the array. So you can e.g. do
my @a = ( 1, 2, 3 );
my @b = ( 4, 5, 6 );
push @a, @b;
to concatenate @a and @b. And it returns the new number of
elements of the array.
Just for the record the last time I
ever used a "push" command was in Z80 ML programming on a Timex
Sinclair 1000 (bout 3 years ago).
It's a bit similar as far as I remember (but it's nearly 20
years since I last used a Z80). There the PUSH command moved
the content of a register onto the stack, automatically de-
crementing the stack pointer by two (and POP moved data back
from the stack into a register and incremented SP twice).
Perl's push() and pop() functions allow you to use each array
as a kind of stack.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- References:
- Textfile to array or hash
- From: J.Gluch
- Re: Textfile to array or hash
- From: Jens Thoms Toerring
- Re: Textfile to array or hash
- From: Bill H
- Textfile to array or hash
- Prev by Date: 5% paypal handling charge supports the online payment! PayPal
- Next by Date: Parse::RecDescent problem regarding rule matching
- Previous by thread: Re: Textfile to array or hash
- Next by thread: Re: Textfile to array or hash
- Index(es):
Relevant Pages
|