Perl-Sensitive Sunglasses | |
PerlMonks |
Re: New Perl user - help with my homeworkby choroba (Cardinal) |
on Dec 25, 2018 at 21:27 UTC ( [id://1227698]=note: print w/replies, xml ) | Need Help?? |
If you tried to calculate the average from the first task for several input numbers, you might noticed there's no need to sum any numbers. So, I'd implement it as
The C-style for loops are randomly used in Perl. Simple while can be used to solve the second task, I tried to show a solution without an array. A little trickery was needed to separate the numbers by spaces.
To filter an array, we usually use grep in Perl. Also, I tried to really ask for 4 input values, not 3, not 12.
For the last task, the repetition operator can hide one level of looping:
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|