Perl: printing an array

The tutor continues about Perl arrays with another trick.

For background, the reader can look up yesterday’s post. The main idea is that an array is a list of values.

Let’s imagine an array declared as follows:

@arr0=(“milk”,”eggs”,”bread”);

To print @arr0 one could use the command

print @arr0;

However, the elements would not be spaced apart; the output would be

milkeggsbread

The same command, but with @arr0 in quotes:

print “@arr0”;

will print the items with spaces in between:

milk eggs bread

Source:

Robert’s Perl tutorial

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply