say length @many_strings; # 1

I think it should be pointed out that in this statement, length puts @many_strings into scalar context, thereby yielding 6 (as shown explicitly in the following line), and then 1 is returned because the length of the string6” happens to be 1. With warnings enabled, this gives a warning, as it should:

17:09 >perl -wE "my @many_strings = ('abc', 'cd', 'e', 'fg', 'hi', 'he +llo world'); say length @many_strings;" length() used on @many_strings (did you mean "scalar(@many_strings)"?) + at -e line 1. 1 17:29 >

For the record, in Raku swl’s use of reduce could be written:

use v6d; my Str @many-strings = |<abc cd e fg hi>, 'hello world'; @many-strings.raku.put; @many-strings.elems.put; say [+] @many-strings.map: { .chars };

Output:

17:09 >raku 2090_SoPW.raku Array[Str].new("abc", "cd", "e", "fg", "hi", "hello world") 6 21 17:09 >

using Raku’s built-in reduction metaoperator [+], documented here.

Hope that’s of interest,

Athanasius <°(((><contra mundum סתם עוד האקר של פרל,


In reply to Re: How to get the TOTAL length/size of an array? by Athanasius
in thread How to get the TOTAL length/size of an array? by Polyglot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.