in reply to Re: Filling a matrix
in thread Filling a matrix

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.)

Replies are listed 'Best First'.
Re^3: Filling a matrix
by Anonymous Monk on Aug 09, 2014 at 19:28 UTC

    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!