>>>>> "APK" == Akhthar Parvez K <akht...@sysadminguide.com> writes:

  APK> Thanks for the explanation John. Could you give one or two real
  APK> time examples where you used a list (instead of an array) except
  APK> in loops such as: for ('a', 'b', 'c', 'd')? I wonder if I'm
  APK> underusing lists in my Perl programs.

it is not a case of choosing which to use. it is understanding the
differences and similarities between them.

lists are temporary lists of values. they are allocated on the stack and
live only within a single expression. lists are initialized one time and
can't be modified (as in changing its length, elements can be modified).

arrays are longer lived lists of values. they are allocated from the
heap and can live between expressions (if they have something that
refers to them that is alive). arrays can be modified (push, pop, etc.),
their length ($#array or @array in scalar context) can be determined.

so it is mostly storage and lifetimes that differentiate lists and
arrays. you can assign each to the other, index them both the same way
(including slicing) and loop over them. but you can't do some things
with lists that you can do with arrays.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to