in reply to Filling a matrix

$totSP = $elohimHash{$folderId}{$customer}{$version}{totSP};

Isn't the {totSP} on the end an error? Shouldn't it be {$totSP}?

Does Perl even support a hash 4 levels deep? What is the limit on that anyway?

Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)

Replies are listed 'Best First'.
Re^2: Filling a matrix
by AppleFritter (Vicar) on Aug 09, 2014 at 16:47 UTC

    Does Perl even support a hash 4 levels deep? What is the limit on that anyway?

    Since multilevel hashes are really just hashes holding references to other (anonymous) hashes, I don't think there is any real limit. Try e.g. the following:

    #!/usr/bin/perl use strict; use warnings; use feature qw/say/; use Data::Dumper; my %hash = (); my $hashref = \%hash; for(1..255) { $hashref = $hashref->{$_} = {}; } print Dumper \%hash;

    This works like a charm and as expected.

    Bisecting this, I found I can go up to 4028 layers of indirection before Perl segfaults at 4029. (And 4028 produces 178 MiB of output from Data::Dumper.)

      Without the print call, there's no problem running it millions deep. What you have is a torture test for the Data::Dumper.

      Also try with $Data::Dumper::Indent = 0; though it still segfaults.

        Without the print call, there's no problem running it millions deep. What you have is a torture test for the Data::Dumper.

        No, it segfaults for me at 4029 even if the Data::Dumper call is commented out. Sorry, I should've made that clearer above.

        And thanks for the tip concerning $Data::Dumper::Indent; good to know!