Creating an Array: Difference between revisions
Content deleted Content added
Added Toka |
|||
Line 296: | Line 296: | ||
==[[Perl]]== |
==[[Perl]]== |
||
[[Category:Perl]] |
[[Category:Perl]] |
||
''' |
'''Interpreter:''' [[Perl]] 5 |
||
my @empty; |
|||
use vars qw{ @Array }; |
|||
⚫ | |||
⚫ | |||
@Array=( |
|||
⚫ | |||
⚫ | |||
# And |
|||
[1,1,1,1,1,1], |
|||
[2,2,2,2,2,2], |
|||
my $aref = ['This', 'That', 'And', 'The', 'Other']; |
|||
[3,3,3,3,3,3] |
|||
print aref->[2]; |
|||
); |
|||
# And |
|||
#You would call the array by this code. This will call the 3rd 1 on the second list |
|||
⚫ | |||
# having to quote like that really sucks, and that's why we got syntactic sugar |
|||
# Alternative: |
|||
my @wakey_wakey = qw(coffee sugar cream); |
|||
push @wakey_wakey, 'spoon'; |
|||
# add spoon to right-hand side |
|||
my $cutlery = pop @wakey_wakey; |
|||
# remove spoon |
|||
unshift @wakey_wakey, 'cup'; |
|||
# add cup to left-hand side |
|||
my $container = shift @wakey_wakey; |
|||
# remove cup |
|||
my @multi_dimensional = ( |
|||
# Alternative: |
|||
⚫ | |||
⚫ | |||
[qw(a b c d e f g)], |
|||
push @Array3, "Item1"; |
|||
[qw(! $ % & *)], |
|||
push @Array3, "Item2"; |
|||
); |
|||
$Array3[2] = "Item3"; |
|||
print $multi_dimensional[1][3]; |
|||
$Array3[3][0] = "Item4"; |
|||
# d |
|||
⚫ | |||
my $mdref = [ |
|||
[0, 1, 2, 3], |
|||
[qw(a b c d e f g)], |
|||
print $ArrayRef->[2]; # would print "And" |
|||
[qw(! $ % & *)], |
|||
]; |
|||
print $mdref->[1][3]; |
|||
# d |
|||
==[[PHP]]== |
==[[PHP]]== |