Perl logo

Perl Refreshments ⌘

Arrays #2.1 - Populating with numbers

As mentioned, arrays hold lists of things, and we showed one way of 'populating' an array in the previous page. However, what if we want to use numbers instead?

If the numbers you want to use are consecutive, there is a much simpler way to create an array to hold them:

my @fooNums = (1..15);

Now that was too easy! Now to print them ...

while(@fooNums) {
     print shift(@fooNums) . "\n";
}

Remember:

-30-