Questions about this topic? Sign up to ask in the talk tab.

Difference between revisions of "Perl/Basics/Variables and Data Types/Arrays"

From NetSec
Jump to: navigation, search
(Created page with "Arrays (or lists) have elements. Typically an array in perl can contain anything - each element can be something different. An array element may be a hash, hash reference, scal...")
(No difference)

Revision as of 03:10, 16 July 2012

Arrays (or lists) have elements. Typically an array in perl can contain anything - each element can be something different. An array element may be a hash, hash reference, scalar, or another array.

Arrays are prefixed by the @ character:

<syntaxhighlight lang="perl">my @messages = ("Hello world!\n","I like perl!\n"); print $messages[0]; print $messages[1]; print "Size of messages array: ". $#messages . "\n"; </syntaxhighlight>

You can access and modify array elements directly:

<syntaxhighlight lang="perl"> $messages[0] = "Hello world!\n"; </syntaxhighlight>