Arrays and Hashes
- From: "Guy" <someone@xxxxxxxxxxxxxxx>
- Date: Sun, 24 May 2009 19:54:49 -0300
Is this correct? The type of parenthesis etc?
Guy
@x; Entire Array
%x; Entire Hash
$x[0]; One item of Array
%x{key}; One item of Hash
$r=\@x; Referencing Array variable
$r=\%x; Referencing Hash variable
@$r; De-referecing entire array
De-referecing entire hash ???
$$r[0]; Referencing one array item
$$r{key}; Referencing one hash item
(v1,v2); Anonymous Array (depending on context)
(k1,v1,k2,v2); Anonymous Hash (depending on context)
[v1,v2]; Reference to Anonymous Array
{k1,v1,k2,v2}; Reference to Anonymous Hash
$a=(1,2,3)[0]; Slice of a list
@x=(1,2,3)[0,1]; Slices of a list
($a,$b)=(1,2,3)[0,1]; Slices of a list
@y=@x[0,1]; Slices of array
@x=@y{k1,k2}; Slices of hash (use @ not % because partial hash)
@x=@y{@keys}; Slices of hash (use @ not % because partial hash)
@x{@keys}=@values; Assigning to specific or all keys of hash
$y[0]=\@x; Creating Array of Array (2D Array)
$y[0][0]; Accessing item
$y[0]=\%x; Creating Array of Hash
$y[0]{key}; Accessing item
$y{key}=%x; Creating Hash of Hash
$y{key}{key2}; Accessing item
.
- Follow-Ups:
- Re: Arrays and Hashes
- From: Ben Morrow
- Re: Arrays and Hashes
- Prev by Date: Re: Is PERL good for a linguist new to programming?
- Next by Date: Re: Is PERL good for a linguist new to programming?
- Previous by thread: FAQ 8.34 I {changed directory, modified my environment} in a perl script. How come the change disappeared when I exited the script? How do I get my changes to be visible?
- Next by thread: Re: Arrays and Hashes
- Index(es):
Relevant Pages
|