I share Laurent_R's confusion about the structure of your data. Here are some general thoughts.
Does this make hash into hashes ...Why not see for yourself?
(See the Data::Dumper module, which is core, for more info.) Is this the data structure you expected? Did you perhaps mean to writec:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dumper; ;; $_ = '-1.23,4...5,6,foo,bar,baz,boff'; ;; my %hash; ;; if (/^\s*(-\d+\.*\d*),(\d+\.*\d*),(\d+\.*\d*),(\S+),(\S+),(\S+),(\S+) +$/) { my $data1 = $1; my $data2 = $2; my $data3 = $3; my $data4 = $4; my $data5 = $5; my $data6 = $6; ;; $hash{data2}{data1}{data3} = $data3; $hash{data2}{data1}{data4} = $data4; $hash{data2}{data1}{data5} = $data5; $hash{data2}{data1}{data6} = $data6; } ;; print Dumper \%hash; " $VAR1 = { 'data2' => { 'data1' => { 'data6' => 'baz', 'data4' => 'foo', 'data3' => '6', 'data5' => 'bar' } } };
Are you aware that the regex
/^\s*(-\d+\.*\d*),(\d+\.*\d*),(\d+\.*\d*),(\S+),(\S+),(\S+),(\S+)$/
has seven capture groups, but you only use six ($data6)? Are you aware that the regex expression \.* matches zero or more . (dot) characters (i.e., it matches '.....')?
Give a man a fish: <%-{-{-{-<
In reply to Re: Parsing a file and storing the data
by AnomalousMonk
in thread Parsing a file and storing the data
by Whiteinch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |