After three days of trying to track down an annoying bug, I finally traced it to this innocuous line, I stripped all the cruft out:

my @t = qw/aA bB cC dD eE fF gG hH iI jJ kK lL mMmM nN oO pP qQ rR sS +tT uU vV wW xX yY Zz/; my $x = 0; $x = length for @t[0 .. 1]; print $x;

What the code is supposed to do is print out "4". Instead it prints out "2". Clearly there is something amiss here.

What I thought the code does is get a slice of @t, loop through the sliced elements in @t, get the length of each one and assign the sum to $x.

I've tweaked this portion of my code for three days and I can't seem to get it behaving right. Ironically, I've actually gotten similar (albeit more convoluted code) actually working in different language. So there is clearly some nuance I'm missing here.


In reply to length of string in array by SavannahLion

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.