Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Creating members of hash of hashes parallelly

by liverpole (Monsignor)
on Jan 07, 2007 at 02:17 UTC ( [id://593363]=note: print w/replies, xml ) Need Help??


in reply to Creating members of hash of hashes parallelly

Hi utku,

If I understand you correctly, the following should work:

use strict; use warnings; use Data::Dumper; my %db_hash; while (<DATA>) { chomp; my ($path, $start, $end, $delay) = split /\s+/, $_; # Get index for this path (if undefined, set it to 1) my $index = ++$db_hash{$path}{'index'}; $db_hash{$path}{$index}{START} = $start; $db_hash{$path}{$index}{END} = $end; $db_hash{$path}{$index}{DELAY} = $delay; } printf "Contents of db_hash => %s\n", Dumper(\%db_hash); __DATA__ my_path /path/3434/some_txt wodo -445 your_path /path/3434/some_txt wodo_modo 41 my_path2 /path/232/wge45 wodo_modo 240 my_path /t43/annow23x /a/b/c/43 NA

Which will yield:

Contents of db_hash => $VAR1 = { 'my_path2' => { '1' => { 'START' => '/path/232/wge45', 'DELAY' => '240', 'END' => 'wodo_modo' }, 'index' => 1 }, 'my_path' => { '1' => { 'START' => '/path/3434/some_txt', 'DELAY' => '-445', 'END' => 'wodo' }, 'index' => 2, '2' => { 'START' => '/t43/annow23x', 'DELAY' => 'NA', 'END' => '/a/b/c/43' } }, 'your_path' => { '1' => { 'START' => '/path/3434/some_txt', 'DELAY' => '41', 'END' => 'wodo_modo' }, 'index' => 1 } };

Update:  Changed print to the printf it was supposed to be (which reveals a mistake I make all the time).  Thanks ysth, for catching that.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Creating members of hash of hashes parallelly
by utku (Acolyte) on Jan 07, 2007 at 03:37 UTC
    Thank you very much folks, you have enlightened the points I could not figure out.

    Both solutions (HoAoH by robotics and japhy; HoHoH by liverpole) worked.
    HoHoH solution has the drawback that the interpreter generates an initialization error during initialization of indices.

    Thanks again for your ultra-fast answers!
      HoHoH solution has the drawback that the interpreter generates an initialization error during initialization of indices.
      How so? Can you show us what you mean?
        Sorry, it was a mistake of my code.

        For HoHoH solution, if I use my own dump routine instead of Dumper:

        foreach $path ( keys %db_hash ) { print "List for $path...\n"; foreach $index ( keys %{ $db_hash{$path} } ) { print "END: ", $db_hash{$path}{$index}{END}, "\n"; } }
        then following comes to stdout:
        Use of uninitialized value in print at ./utk.pl line 66, <FH> line 246 +99. Use of uninitialized value in print at ./utk.pl line 66, <FH> line 246 +99.
        line 66 is the line of "print END" routine. In this case,
        $db_hash{$path}{$index}{END}
        tries to access
        $db_hash{$path}{'index'}{END}
        ... which does not exist anyway. It was a mistake that I did not use the Dumper.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593363]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2025-07-14 06:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.