Perl Programming

CSE3395




Lecture 3: Lists and Arrays


E-mail this post



Remember me (?)



All personal information that you provide here will be governed by the Privacy Policy of Blogger.com. More...



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

      Convert to boldConvert to italicConvert to link

 


Previous posts

Archives

Links