3 ms·
Perl also lets you nest data structures, no brain twisting involved. Perl doesn't have Tuples natively but you can add them with a module. You can also nest obj
by 0xbadcafebee 1y ago
Perl also lets you nest data structures, no brain twisting involved. Perl doesn't have Tuples natively but you can add them with a module. You can also nest objects in complex data structures.
perl <<'EOF'
my $object = bless sub { my ($s) = @_; if ($s eq "thingy") { return("hello world!") } else { return("goodbye world!") } };
my %hash1 = ( baz => "here we go", foo => $object );
my @array1 = ( undef, undef, undef, \%hash1 );
my %hash2 = ( bar => \@array1 );
my $reference = \%hash2;
print( $reference->{bar}->[3]->{baz}, "\n" );
print( $reference->{bar}->[3]->{foo}->('thingy') , "\n" );
print( $reference->{bar}->[3]->{foo}->('something') , "\n" );
EOF
here we go
hello world!
goodbye world!
Perl being Perl, TMTOWTDI, but you can enforce your own style using linters and formatters.