The problem seems to be the absence of types in Perl: if DiveVal encounters a number, it creates an array for you, not a hash:
$ perl -MData::Dumper -MData::Diver=DiveVal -E 'DiveVal($x = {}, qw(1 +2 3)); say Dumper $x' $VAR1 = { '1' => [ undef, undef, [ undef, undef, undef, undef ] ] };

BTW, I had to rewrite your code to be able to understand what it does:

#!/usr/bin/perl use warnings; use strict; use File::Find; use Data::Dumper; use Data::Diver qw (DiveVal); my @extracted = <DATA>; push @extracted, 'end'; my @currentpath = (); my $structure = {}; for my $i (0 .. $#extracted) { my @list = split /;/, $extracted[$i]; my @list2 = split /;/, $extracted[$i+1]; if ($list2[0] eq 'end') { last } if ($list2[0] gt $list[0]) { push @currentpath, $list[1]; } else { my @req = (@currentpath, $list[1], 'required'); DiveVal($structure, @req) = $list[3]; pop @currentpath if $list2[0] lt $list[0]; } } print Dumper($structure);

Update: See Re^3: Parsing a dataset into an arbitrary sized hash of hashes on how to fix the problem (line 28 of my code).

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re: Parsing a dataset into an arbitrary sized hash of hashes by choroba
in thread Parsing a dataset into an arbitrary sized hash of hashes by DunLidjun

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.