Jump to content

Creating an Array: Difference between revisions

(Added Toka)
Line 296:
==[[Perl]]==
[[Category:Perl]]
'''InterpeterInterpreter:''' [[Perl]] 5
 
my @empty;
use vars qw{ @Array };
my @Array3empty_too = ();
 
my @Arraypopulated = ('This', 'That', 'And', 'The', 'Other');
@Array=(
print $Arraypopulated[1][32];
[0,0,0,0,0,0],
# 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
print $Array[1][3];
 
# having to quote like that really sucks, and that's why we got syntactic sugar
# Alternative:
my @array_using_qwwakey_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:
[0,0 1,0 2,0,0,0 3],
my @Array3 = ();
[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
 
@Array = ('This', 'That', 'And', 'The', 'Other');
my $mdref = [
 
$ArrayRef = ['This'0, 'That'1, 'And'2, 'The', 'Other'3];,
[qw(a b c d e f g)],
print $ArrayRef->[2]; # would print "And"
[qw(! $ % & *)],
];
print $mdref->[1][3];
# d
 
==[[PHP]]==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.