Defining and Using Lists and Arrays

The care and feeding of the wily Perl array includes defining it, assigning it to an array variable, sticking elements in and taking them out, and finding out its length (the number of elements). There are also a whole lot of things you can do to manipulate arrays and their data, but let's start with the basics.

Unlike other languages, in which arrays have to be carefully set up before you can use them, arrays in Perl magically appear as you need them and happily grow and shrink to the number of elements you have in them at any given time. They can also contain any kind of scalar data: numbers, strings, or a mix of both, and as many elements as you want, limited only by the amount of memory you have available. ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.