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

Perl/Basics/Variables and Data Types/Arrays

From NetSec
Revision as of 03:10, 16 July 2012 by AlizaLorenzo (Talk | contribs) (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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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>