In fact, you're not even going to see
my $sizeofstring = length($string);
That's because "length" has been deemed to be an insufficiently specified concept, because it doesn't specify the units. Instead, if you want the length of something in characters you use
my $sizeinchars = chars($string);
and if you want the size in elements, you use
my $sizeinelems = elems(@array);
This is more orthogonal in some ways, insofar as you can now ask for the size in chars of an array, and it will add up all the lengths of the strings in it for you:
my $sizeinchars = chars(@array);
And if you ask for the number of elems of a scalar, it knows to dereference it:
my $ref = [1,2,3]; my $sizeinelems = elems($ref);
These are, in fact, just generic object methods:
@array.elems $string.chars @array.chars $ref.elems
And the functional forms are just method calls in disguise.

So maybe length() is a bad example now. Sorry. :-)

By the way, you can also use %hash.elems, which returns the number of pairs in the hash. I don't think %hash.chars is terribly useful, but it will tell you how many characters total there are in both keys and values.

Actually, the meaning of .chars varies depending on your current level of Unicode support. To be more specific, there's also:

$string.bytes $string.codepoints $string.graphemes $string.letters
...none of which should be confused with:
$string.columns
or its evil twin:
$string.pixels

In reply to Re: Re: Re^4: Perl6 syntax being too much complex? How we will teach and read that?! by TimToady
in thread Perl6 syntax being too much complex? How we will teach and read that?! by gmpassos

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.