Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference to an anonymous hash

Status
Not open for further replies.

naq2

Programmer
Aug 3, 2004
74
FR
How to write a reference to an anonymous hash?

For an array, it would be:
Code:
$rArray = \(1, 2, 3, 4) ;

Thanks for you help.
 
The answer is:
Code:
$rHash = {"key1" => 'val1', "key2" => 'val2, "key3", 'val3'} ;

Simply!

Thanks for my help! :)
 
Actually, you're incorrect about the arrayref. Using the \( . . . ) syntax returns a list of references, rather than a reference to an array. In your original code, $rArray will be a reference to a the last scalar in the list, namely 4. The correct syntax for an arrayref is to use square brackets:

Code:
$rArray = [ 1, 2, 3, 4 ];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top