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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-06-23 04:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.