Chas Owens wrote:
The current Perl 5 behavior is
[EMAIL PROTECTED]:~$ perl -le 'my @a = ("-" x 5, "foo", "-" x 5); print "@a"'
----- foo -----
[EMAIL PROTECTED]:~$ perl -le 'my @a = (("-") x 5, "foo", ("-") x 5); print
"@a"'
- - - - - foo - - - - -
I am against anything other than that for x or xx without a really
compelling reason.
...with x always corresponding to the first and xx always
corresponding to the second, right? In essence, x always produces a
string, while xx always produces a list.
Jonathan Lang wrote:
> Personally, I would tend to favor the notion that infix:<x> always
> produces a single string. With this in mind, I'm now leaning toward
> "~cat($a xx $n)" as the more verbose equivalent of "$a x $n". You
> always produce a single string, and you do so lazily (according to the
> way that 'cat' works in item context).
I assume it is a bug in Pugs implementation of cat, but
pugs> ~cat('a' xx 5)
"a a a a a"
Yes, that would be a bug - probably closely tied to the fact that pugs
doesn't implement cat properly in item context. IIRC, the original
inspiration for the 'cat' function was 'concatenate' - thus, in item
context at least, one would expect 'cat' to resemble '[~]'.
I also am having a hard time figuring out why I would want an infinite
string. My first thought was something like
my $ten_zeros = substr(cat(0 xx *), 0, 10);
but that is more clearly written as
my $ten_zeros = 0 x 10;
I'll punt the practical usage to someone else, other than to suggest
that the goal of using an asterisk for the number of repetitions isn't
so much to produce an "infinite string" as a "string of arbitrary
length". Remember, '*' ne 'Inf'; '*' eq 'Whatever'. A practical use
for '~cat($string xx *)' would most likely be one that relies on the
arbitrariness of the number of repetitions. Hmm... how about
something like:
if $a gt ~cat('-' xx *) { ... }
or, if 'x' is defined along the lines that I'm considering:
if $a gt '-' x * { ... }
Bear in mind that you're not limited to single-character repetitions:
if $a lt '142857' x * { ... }
In short, the string will get replicated exactly as many times as is
needed to resolve the comparison.
--
Jonathan "Dataweaver" Lang