develooper Front page | perl.perl6.users | Postings from August 2020

Any other way to do this

Thread Next
From:
Radhakrishnan Venkataraman
Date:
August 31, 2020 15:49
Subject:
Any other way to do this
Message ID:
CAAxMQoAX3j=EDUGHOa8=2rqGkux-+0p9Jf3J5uiB+WcYhZfmYQ@mail.gmail.com
Please see the following script that checks for type and sums up only the
numbers passed as arguments to the script in the command line.  I would be
grateful if any improvement or furtherance to this script is offered.
Thank you.

#
# sums the numbers given in command line arguments and prints
#
my $sum = 0;
for @*ARGS
{
$sum += $_.Rat if $_.Int // 0 !=== 0;
}
say $sum;

#
# command line execution
# perl6 cla.p6 100 200 300 apples 400oranges 2kilos 18.7876 500 grams14
10stars10 sun100moon 77
#

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About