The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Read csv into Hash array? kinmak Shell Programming and Scripting 1 05-07-2008 10:35 AM
perl array question from going through hash hankooknara Shell Programming and Scripting 2 07-29-2007 09:53 PM
hash,array and perl new2ss Shell Programming and Scripting 3 05-23-2007 11:30 AM
md5 hash a string or char array in SCO jcarter2333 High Level Programming 5 02-08-2007 04:09 PM
getting data list into a hash array topcat8 Shell Programming and Scripting 5 03-09-2004 12:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-10-2006
jsmoriss jsmoriss is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 1
Hash within array, within hash, within array...

I have a little problem. To keep a configuration simple, I've exceeded my perl knowledge. :-) I've worked with multi-dimentional arrays before, but this one has me beat:

Code:
@info = (
    {
        'defval' => 'abc'
        'stats' = (
            { 'name' => 'a', },
            { 'name' => 'b', },
        ),
    },
    {
        'defval' => 'def'
        'stats' = (
            { 'name' => 'd', },
            { 'name' => 'e', },
        ),
    },
);

my @infolist = $info[0]->{stats};    # I have a feeling this is where I'm going wrong...

print $infolist[0]->{name};    # <-- works!
print $infolist[1]->{name};    # <-- does not!
Like I said, I've exceeded my perl knowledge. :-) Can anyone see where I'm going wrong? The idea, of course, is to be able to get those 'name' key values... :-)

Thanks,
js.
  #2 (permalink)  
Old 07-10-2006
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
I have no idea why you said one of the statements worked, because your entire snippet was full of errors, and I confirmed that by running on my machine with compilation errors.

Not sure whether my modified version is what you intended.

Code:
@info = (
    {
        'defval' => 'abc',
        'stats' => [
            { 'name' => 'a', },
            { 'name' => 'b', },
        ],
    },
    {
        'defval' => 'def',
        'stats' => [
            { 'name' => 'd', },
            { 'name' => 'e', },
        ],
    },
);

my $r_infolist = $info[0]->{stats}; 

print $r_infolist->[0]{name};    # <-- a
print $r_infolist->[1]{name};    # <-- b
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0