in reply to Extracting numbers from arrays
Have fun with the rest of your homework.use strict; my ($first, $last) = @ARGV; # Pass the values in my @nums = 1 .. 100; my $inside = 0; my @inside_nums; foreach my $num (@nums) { if ($num == $first) { $inside = 1; } if ($inside) { push @inside, $num; } if ($num == $last) { $inside = 0; } } print "@inside\n"; #### for-loop could also be written as: my $inside; foreach my $num (@nums) { $inside = 1 if $num == $first; push @inside_nums, $num if $inside; $inside = 0 if $num == $last; }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
|---|