jar00n has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Seemingly odd behavior of sequence
by oiskuu (Hermit) on Dec 04, 2013 at 11:47 UTC | |
by jar00n (Novice) on Dec 05, 2013 at 09:43 UTC | |
|
Re: Seemingly odd behavior of sequence
by Kenosis (Priest) on Dec 04, 2013 at 17:27 UTC | |
by jar00n (Novice) on Dec 05, 2013 at 09:44 UTC | |
by Kenosis (Priest) on Dec 06, 2013 at 16:49 UTC |