I noticed a hash object was once defined as in the following:
my %data = ();
$data{file} = $file;
$data{concept} = $#row;
$data{line1} {$cell[0]} = $cell[1];
What does this hash construction process try to achieve? Or what is the difference between
$data{concept} = $#row;
and
$data{line1} {$cell[0]} = $cell[1];
?
Output:
I think
$data{line1} {$cell[0]}is better written as$data{line1}{$cell[0]}or (my preference)$data{line1}->{$cell[0]}.I included the scalar
$fileand the arrrays@rowand@cellto demonstrate what your code means.adds the contents of
$fileto your hash with the keyfile.adds the last index of
@rowto your hash with the keyconcept. In my example the last index is2, since the indexes in@roware0,1and2.adds a hash ref to your hash with the key
line1(through autovivification) and adds the element$cell[1]to this hash ref with the key$cell[0]. Autovivification in this case means that Perl associatesline1with a hash ref and creates it, because you’re accessing it with{$cell[0]}. That saves you the trouble of having to write: