in reply to difference between array and list in perl
@list1, @list2, @arr1, and @arr2, are all arrays. In all your examples the right hand side of the assignments are lists, although the list (list1, list2, list3, list4) is questionable, since it contains bare words which might be interpreteted as subroutine calls. To ensure text you can autoquote each word using qw, for example:@list1 = (1,2,3,4); @list2 = (list1, list2, list3, list4); @arr1 = ("1" , "2", "3", "4"); @arr2 = ("arr1", "arr2", "arr3", "arr4") ;
qw returns a list (in an old release it used to return an array, and that was considered to be a bug).my @arr3 = qw(value1 value2 value3 value4);
will assign the three values to the array, then assign from the array into the three variables $speed, $colour, $animal arranged in a list.my @arr5 = qw (quick brown fox); my ($speed, $colour, $animal) = @arr5;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: difference between array and list in perl
by JavaFan (Canon) on Jan 16, 2010 at 22:42 UTC | |
by ikegami (Patriarch) on Jan 17, 2010 at 07:23 UTC | |
by LanX (Saint) on Jan 17, 2010 at 01:02 UTC | |
by JavaFan (Canon) on Jan 17, 2010 at 14:13 UTC |