Robert's Perl Tutorial

http://www.sthomas.net/roberts-perl-tutorial.htm


Jiggerypokery with Arrays

@names=("Muriel","Gavin","Susanne","Sarah");
@cities=("Brussels","Hamburg","London","Breda");

&look;

$last=pop(@names);
unshift (@cities, $last);

&look;

sub look {
        print "Names : @names\n";
        print "Cities: @cities\n";
}

Now we have two arrays. The pop function removes the last element of an array and returns it, which means you can do something like assign the returned value to a variable. The unshift function adds a value to the beginning of the array. Hope you didn't forget that &subroutinename calls a subroutine. Presented below are the functions you can use to work with arrays: