I'm fairly new to Perl and my searches for an answer to this question drew thousands of irrelevant matches due to the vagueness of my issue. I was toying with repeating a sequence and Perl appears to be doing arithmetic with the 'x' operator:

#!/usr/bin/perl use strict; use warnings; print "Enter some strings:\n"; my @lines = <>; print 0..9 x 2, "\n"; foreach (@lines) { printf "%20s", $_; }

This produces a header line:

$ ./ex05-02.pl Enter some strings: asdfasdfasdf asdfa asdfasdfasd asdf 0123456789101112131415161718192021222324252627282930313233343536373839 +404142434445464748495051525354555657585960616263646566676869707172737 +475767778798081828384858687888990919293949596979899 asdfasdfasdf asdfa asdfasdfasd asdf

Not 01234567890123456789 as I had expected it to, ultimately I wanted a 20 character header but 0..9 x 2 is being interpreted unexpectedly for me. I would love for anyone to be able to shed some light on why this happening.


In reply to Seemingly odd behavior of sequence by jar00n

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.