Wow imagine having to wait for your computer to turn on before you could use it!
You can pretty much chuck any scalar into an array in Perl.
Arrays grow in size depending on what you access.
$#array returns the highest index -1.
Lists
A list is an expression containing an ordered sequence of scalars
THIS IS PERL.
Arrays and Lists.
A list literal is an expression containing an ordered sequence of scalars.
An array is best used when initialised by a list, so that you can index it and step through it and do all kinds of nifty things like that.
There are various ways to assign a list of words to an array. You can reference the entire array with the @ sign. The $ sign is for individual indexed elements.
Now you can do @animal = qw(Dog cat wildebeest);
And that's it :-D
(This just from Mum: "Did you go to Mardi Gras?"
Me: "No! I'm in Clayton learning about Perl Programming hehehe").
Arrays and scalars occupy different name-spaces. @x and $x[...] refers to array var @x
$x refers to scalar var $x
Arrays cannot contain arrays.
Lots of handy things you can now do.
@items = sort @items;
print sort qw(c a t); # Prints act
qw creates a list containing all the elements. It's the same as print sort ("c", "a", "t");
Array Functions
push pop
unshift shift
0 Responses to “Lecture 3: Lists and Arrays”
Leave a Reply