
October 11th, 2012, 02:32 AM
|
 |
!~ /m$/
|
|
Join Date: May 2004
Location: Reno, NV
|
|
You should begin using strict mode in all your code. It will help you understand the scope of your variables.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw/sum/;
my $x = 10;
my $y = 100;
my @multiples;
for ($x .. $y) {
push @multiples, $_ if ($_ % 4 == 0);
}
my $sum = sum @multiples;
print "Multiple of four between $x and $y are: ";
print join ", ", @multiples;
print "\nSum of multiples: $sum\n";
|