CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
how to get the hash key of array hash

 



gkgana
Novice

Mar 7, 2008, 6:21 PM

Post #1 of 10 (1094 views)
how to get the hash key of array hash Can't Post

Hi Friends,

In my test Case I am having the following line:

my @availSpaceResult = $fsFTA->cmd_fs_get_space({ name => $rootDir});

cmd_fs_get_space will return the following value to @availSpaveResult

0

'0'

{

'free_space' => '119214080',

'total_space' => '127989760'

}

If I want to get the value of hash key 'free_space', I can use like

my $availSpace = $availSpaceResult[2]{free_space};

now $availSpace having the value 119214080.

My requirement here is, I want to use hash key index instead of key value(free_space). Because for some other commands keys may be different.

Please help me out on this.

Thanks & Regards,

Ganapathi.




KevinR
Veteran


Mar 8, 2008, 1:39 AM

Post #2 of 10 (1090 views)
Re: [gkgana] how to get the hash key of array hash [In reply to] Can't Post


Code
foreach my $keys (keys %{$availSpaceResult[2]}) { 
print "$keys = $availSpaceResult[2]{$keys}\n";
}

-------------------------------------------------


gkgana
Novice

Mar 10, 2008, 10:33 AM

Post #3 of 10 (1083 views)
Re: [KevinR] how to get the hash key of array hash [In reply to] Can't Post

Hello Kevin,

Thank you for your help.

With Regards,

Ganapathi.


gkgana
Novice

Jul 29, 2008, 9:25 PM

Post #4 of 10 (1011 views)
Re: [gkgana] how to get the hash key of array hash [In reply to] Can't Post

Hello Kevin,

I hope you are fine and doing good.

I need a help from you to get bd_addr key value from bellow hash. Can you please help me out.

{

'dev_info' => [

{

'1' => {

'bonded_state' => '1',

'manuf_id' => '15',

'bd_addr' => '0x0018f8899548',

'minor_devclass' => '257',

'security' => '0',

'lmp_subversion' => '777',

'linkkey_type' => '0 ',

'lmp_feature' => '0xfffe0d',

'lmp_version' => '2',

'bt_nickname' => 'NULL',

'srvc_class' => '114',

'major_devclass' => '256'

}

}

]

}



With Regards,

Ganapathi.


gkgana
Novice

Jul 29, 2008, 9:26 PM

Post #5 of 10 (1010 views)
Re: [KevinR] how to get the hash key of array hash [In reply to] Can't Post

Hello Kevin,

I hope you are fine and doing good.

I need a help from you to get bd_addr key value from bellow hash. Can you please help me out.

{

'dev_info' => [

{

'1' => {

'bonded_state' => '1',

'manuf_id' => '15',

'bd_addr' => '0x0018f8899548',

'minor_devclass' => '257',

'security' => '0',

'lmp_subversion' => '777',

'linkkey_type' => '0 ',

'lmp_feature' => '0xfffe0d',

'lmp_version' => '2',

'bt_nickname' => 'NULL',

'srvc_class' => '114',

'major_devclass' => '256'

}

}

]

}



With Regards,

Ganapathi.


KevinR
Veteran


Jul 29, 2008, 11:19 PM

Post #6 of 10 (1008 views)
Re: [gkgana] how to get the hash key of array hash [In reply to] Can't Post

Is that some perl data or is that text in a file? Its not making sense to me.
-------------------------------------------------


gkgana
Novice

Jul 30, 2008, 7:36 AM

Post #7 of 10 (994 views)
Re: [KevinR] how to get the hash key of array hash [In reply to] Can't Post

Hello Kevin,

perl subroutine returns that data to vatiable.

With Regards,

Ganapathi.


KevinR
Veteran


Jul 30, 2008, 9:24 AM

Post #8 of 10 (990 views)
Re: [gkgana] how to get the hash key of array hash [In reply to] Can't Post

Sorry but the data structure is not making sense to me, I can't tell if it is a hash of arrays of hashes or an array of array of hashes or some variation of that.
-------------------------------------------------


gkgana
Novice

Jul 30, 2008, 10:37 AM

Post #9 of 10 (987 views)
Re: [gkgana] how to get the hash key of array hash [In reply to] Can't Post

Hi all,



I got it, the way is

$result_string2->{'dev_info'}->[0]->{'1'}->{'bd_addr'};


KevinR
Veteran


Jul 30, 2008, 1:26 PM

Post #10 of 10 (981 views)
Re: [gkgana] how to get the hash key of array hash [In reply to] Can't Post

Very good.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives