use List::Util qw /reduce/;
say reduce { $a + length $b } 0, @many_strings;
For cheap thrills, I browsed List::MoreUtils but nothing jumped out at me.
This one is similar to yours (both programs produce 21):
use v5.38;
use List::MoreUtils qw/reduce_0/;
my @many_strings = ("abc", "cd", "e", "fg", "hi", "hello world");
say reduce_0 { $a + length $b } @many_strings;
I'm always out-classed by tybalt89 in these kinds of challenges,
so I look forward to seeing what concoctions he comes up with when the USA time zone kicks in. :)
References Added Later
Perl core:
CPAN:
- Data::Dump by Breno G. de Oliveira
- List::Util by Paul Evans - core module
- List::MoreUtils by Jens Rehsack
- List::AllUtils by Dave Rolsky
- List::SomeUtils by Dave Rolsky
- List::UtilsBy by Paul Evans (some of these might be later merged into core List::Util)
- List::Gen by Eric Strom - provides functions for generating lists; provides higher order functions, list comprehensions, generators, iterators, and other utility functions for working with lists
Other:
See Also
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.