I create an array of hashes of arrays
my @array = (
{label => 'first hash'},
{label => 'second hash',
innerarray => [
{label => 'first inner hash'},
{label => 'second inner hash'},
]
},
);
Is there a way to add a second internal hash only if the condition is filled? Something like that:
my @array = (
{label => 'first hash'},
{label => 'second hash',
innerarray => [
{label => 'first inner hash'},
{label => 'second inner hash'} if 1==1,
]
},
);
I tried to rewrite my code with push:
my @innerarray = ();
push @innerarray, {label => 'first inner hash'};
push @innerarray, {label => 'second inner hash'} if 1==1;
my @array = (
{label => 'first hash'},
{label => 'second hash',
innerarray => \@innerarray
},
);
But it becomes very illegible, since I have to predefine all internal arrays before using them, which in some cases amounts to several 100 lines of code above use.
Is there a way to add an if condition directly where I insert an array element?
source
share