I could't help but notice that your array just screams to be an array of arrays. I say this because it regularly repeats itself every three elements. I know this wasn't your original spec, but I offer the following advice.
If you structured your array as:
my @array = qw/ create mount remove /; my $array = [ ['create', 'mount', 'remove'], ['create', 'mount', 'remove'], \@array, # essentially the same values \@array, ... ];
... then you could easily add items to the end of each of sub-array by iterating and pushing:
#!/perl/bin/perl use strict; use warnings; use Data::Dumper; for my $subarray (@$array) { push(@$subarray, 'foo'); } print Dumper($array);
__OUTPUT__ $VAR1 = [ [ 'create', 'mount', 'remove', 'foo' ], [ 'create', 'mount', 'remove', 'foo' ], [ 'create', 'mount', 'remove', 'foo' ], [ 'create', 'mount', 'remove', 'foo' ], ];
In reply to Re: Adding an new element after every 5th element in array
by thezip
in thread Adding an new element after every 5th element in array
by dvinay
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |