Stanisław Findeisen wrote:
This short program:

#!/usr/bin/perl

use warnings;
use strict;

use List::Util qw(sum);

# The above statement imports the sum() sub


my %h  = (1 => 5, 2 => 7, 5 => 18);
my $sk = List::Util->sum(keys   %h);
my $sv = List::Util->sum(values %h);

# The two above statements can be replaced with:
my $sk = sum(keys   %h);
my $sv = sum(values %h);


print("Sum of keys:   $sk\n");
print("Sum of values: $sv\n");

my @lk  = (12, 3, 8);
my $lks = List::Util->sum(@lk);

my $lks =sum( @lk );

print("Sum of lk:     $lks\n");



--
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to