Search code examples
perlhashperl-data-structures

Perl hash of hashes and array - print the array contents


Have the below data structure. I want to print the entire array for the key TUESDAY. Tried the below way but it's not working. I don't want to have an additional statement of taking the array reference to a variable and printing out later. I want to do it in single statement in the print function.

my $FILE_LIMIT = {
    CHECK => "ON",
    ISANE => {
        CHECK     => "ON",
        MONDAY    => 33,
        TUESDAY   => [10, 20, 30, 40],
        WEDNESDAY => 12,
        THURSDAY  => 13,
        SATURDAY  => 14,
        SUNDAY    => 15
    } };

print "array val: " . $FILE_LIMIT->{ISBANE}->{TUESDAY}[1 .. $#] . "\n";

Solution

  • print "array val: " . join (' ', @{ $FILE_LIMIT->{ISANE}->{TUESDAY} }), "\n";