Monday, 14 January 2013

Perl Notes - Arrays


Arrays

Features
All purpose array/list type container built in to language
Arrays know their length
Can change size dynamically
Can contain different types of elements (strings, ints, ... at the same time)
@a = (1, 2);
$x = $a[1]; ## look at the [1] element
$a[0] = 13; ## change the [0] element
shift / unshift – operate on "front" or [0] of the array
shift(@a); ## return and remove [0] element
unshift(@a, "hello"); ## insert element at front
push / pop – operate on "end or [len-1] of the array
pop(@a);
push(@a, "hello");
@ARGV

No comments:

Post a Comment