Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: hash magic

by BrowserUk (Pope)
on Mar 14, 2013 at 13:35 UTC ( #1023477=note: print w/replies, xml ) Need Help??


in reply to hash magic

#! perl -slw use strict; use Data::Dump qw[ pp ]; my %hash; while( <DATA> ) { chomp; my $r = \%hash; my @bits = split '\s+->\s+|_', $_; $r = $r->{ shift( @bits ) } //= {} while @bits > 2; $r->{ $bits[ 0 ] } = $bits[ 1 ]; } pp \%hash; __DATA__ Host_001 -> objectID -> HOST.62 Host_001 -> name -> rapidqa Host_001_WWN_001 -> WWN -> 21.00.00.E0.8B.80.7E.7D Host_001_WWN_002 -> WWN -> 21.00.00.E0.8B.80.E7.7F Host_001_LogicalUnit_001 -> objectID -> LU.R700.87108.8234 Host_001_LogicalUnit_001 -> devNum -> 8234 Host_001_LogicalUnit_002 -> objectID -> LU.R700.87108.8235 Host_001_LogicalUnit_002 -> devNum -> 8235 Host_002 -> objectID -> HOST.107 Host_002 -> name -> sapfvir03 Host_002_WWN_001 -> WWN -> 21.00.00.E0.8B.81.D7.F6 Host_002_WWN_002 -> WWN -> 21.00.00.E0.8B.81.4C.F9 Host_002_LogicalUnit_001 -> objectID -> LU.R700.87108.10336 Host_002_LogicalUnit_001 -> devNum -> 10336

Outputs:

C:\test>junk92 { Host => { "001" => { LogicalUnit => { "001" => { devNum => 8234, objectID => "LU.R7 +00.87108.8234" }, "002" => { devNum => 8235, objectID => "LU.R7 +00.87108.8235" }, }, WWN => { "001" => { WWN => "21.00.00.E0.8B.80.7E.7D" } +, "002" => { WWN => "21.00.00.E0.8B.80.E7.7F" } +, }, name => "rapidqa", objectID => "HOST.62", }, "002" => { LogicalUnit => { "001" => { devNum => 10336, object +ID => "LU.R700.87108.10336" } }, WWN => { "001" => { WWN => "21.00.00.E0.8B.81.D7.F6" } +, "002" => { WWN => "21.00.00.E0.8B.81.4C.F9" } +, }, name => "sapfvir03", objectID => "HOST.107", }, }, }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: hash magic
by hrmnbth (Initiate) on Mar 14, 2013 at 14:10 UTC

    Thank you all, you are beeeeatiful

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023477]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2016-12-09 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (148 votes). Check out past polls.