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$..$/

In reply to Re: Creating members of hash of hashes parallelly by liverpole
in thread Creating members of hash of hashes parallelly by utku

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.