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