Hi anonymous monk, yes I'm still finding this confusing.
Well hold onto your pants :)
You mentioned it is confusing $dataset for a hashref.
Look at the
@beef equivalent example, it is this line that dies with Can't use an undefined value as an ARRAY reference
my @beef = @{ $dataset->{ $col[0] } };
This line is really
my $key = $col[0] ;
my $meat = $dataset->{ $key };
my @beef = @{ $meat };
I misspoke when I said it is confusing $dataset for a hashref , in actuality, $dataset is a hashref.
The problem is, $key is not in $dataset, so $meat is undef
Since meat is undef, trying to treat $meat as an array by de-referencing it, triggers a warning if you have warnings on, and triggers an error, if you have strict on.
## no warnings or errors
$ perl -e "print @{ undef() }; print 6"
6
## a warning is issued, but 6 still gets printed
$ perl -we "print @{ undef() }
Use of uninitialized value in array dereference at -e line 1.
6
## with strict the warning is fatal, 6 not printed cause program died
$ perl -Mstrict -we "print @{ undef() }
Can't use an undefined value as an ARRAY reference at -e line 1.
See References quick reference
To avoid this error, you might add
next unless $meat;
You don't want to disable strict :)
Lets take apart a simpler example, one that builds @data
|