|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
If I throw an array inside of a hash:
%somehash = ('somekey', ['one', 'two']) how do I get the array back out? I get can individual values from the array with: $somehash{somekey}[0] but if I try to get the entire array: @somehash{somekey} I get some funky array junk: Arrayx18748210 Any ideas? |
|
#2
|
||||
|
||||
|
Try:
@{$somehash{somekey}} That will give you back your array of "one two". Mickalo
__________________
Thunder Rain Internet Publishing Custom Programming & Database development Providing Personal/Business Internet Solutions that work! |
|
#3
|
|||
|
|||
|
I would do some research on references with Perl. When you tried:
Code:
@somehash{somekey}
Code:
ARRAYx18748210 You were dealing with references. Your result was a description of the data type held in a memory address - ARRAY - and the actual memory address - x18748210. This is a reference or a "pointer" to the address that a variable is stored in. References are good for saving memory space and CPU time. You did it in a really funky way. With a non-referenced HASH but a referenced element to that hash. A more consistent way to do this would have been. [code] $somehash = { 'somekey' => ["one","two"], 'anotherkey' => ["three","four"], }; print @{$somehash->{'somekey'}}, "\n"; # This would dereference and print one of your entire arrays
__________________
- dsb - ![]() Perl Guy |
|
#4
|
|||
|
|||
|
That's the ticket. Thanks guys.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > How to get an array back out of a hash? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|