I know it's possible to declare an array like this:
my @array = ( 5 .. 10 );
which is equivalent to:
my @array = ( 5, 6, 7, 8, 9, 10 );
but is there a similar shorthand when the incremental value is greater than one e.g.
my @array = ( 5, 10, 15, 20, 25 );
my @array = ( 100, 200, 300, 400, 500 );
my @array = map 5*$_, 1..5;
and
my @array = map 100*$_, 1..5;
More generally:
my $start = 5;
my $stop = 25;
my $increment = 5;
my @array = map $start+$increment*$_, 0..($stop-$start)/$increment;
or:
chomp(my @array = `seq $start $increment $stop`);
(Just kidding.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With