Eric at Lucii.org on 20 Jan 2011 11:45:13 -0800 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PLUG] perl question |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have a data structure in perl: @output It is sparse (not all indexes have values.) Those that do look like this example which would be something like $output[5]: $VAR1 = { '128' => { 'salutation' => 'Dr.', 'area' => '800', 'spec_link' => '131', 'state' => 'PA', 'last_name' => 'Smith', 'dr_id' => '1', 'city' => 'Swarthmore', 'middle' => 'A', 'active' => undef, 'phone' => '555-1212', 'description' => 'some description goes here', 'sex' => 'M', 'address2' => '', 'loc_no' => '1', 'zip' => '19067', 'title' => 'DMD', 'address1' => '123 Any Street.', 'first_name' => 'John' } }; When I put data in the element I do it like this: $var1 = 5 ; $var2 = 128 ; $output[$var1]->{$var2}->{'description'} = "some description goes here" ; To get the data out I walk through the array, skipping indexes where there is no data. Once I find an array element with data I want to access the elements. Currently, the only way I can get to it is to use Dumper to produce the above print out. How do I find out what the {'128'} value is so that I can address the elements? I tried this: for ( $x = 0; $x < $#output; $x++ ) { next if not defined $output[$x] ; $hashKey = keys $output[$x] ; print "record: $x has last name of: " . $output[$x]->{$hashKey}->{'last_name'} ; } ... but perl barfs on the use of keys Type of arg 1 to keys must be hash (not array element) at ./build_fast_doc.pl line 229, near "] ;" What am I missing here? I thought the array elements here ARE hashes. BTW: This is perl, v5.8.7 Thanks, Eric - -- # Eric Lucas # # "Oh, I have slipped the surly bond of earth # And danced the skies on laughter-silvered wings... # -- John Gillespie Magee Jr -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk04kKUACgkQ2sGpvXQrZ/469gCeJYSGZV/IF/PYECHlTYK6k5Iq Up0AmwdPj0XPbhl1asrADLj4bsqVn2To =CiFX -----END PGP SIGNATURE----- ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug