D
Dan Wilga
I've run into something that has me totally puzzled. If I do this:
print "foo".("." x 5);
as expected, I get:
foo.....
However, if I do:
print ("." x 5)."foo";
I get only:
.....
Why does the "foo" get discarded?
I can get around this by changing the code to:
print scalar("." x 5)."foo"
But, according to perlop, I wouldn't think this should be necessary:
"In scalar context or if the left operand is not enclosed in
parentheses, it returns a string consisting of the left operand repeated
the number of times specified by the right operand."
Shouldn't the use of the '.' operator outside be sufficient to cause the
parenthetical part to be considered a scalar? Even if it's not, and the
bit inside the parens evaluates to a single-element list, I would still
expect to see:
1foo
print "foo".("." x 5);
as expected, I get:
foo.....
However, if I do:
print ("." x 5)."foo";
I get only:
.....
Why does the "foo" get discarded?
I can get around this by changing the code to:
print scalar("." x 5)."foo"
But, according to perlop, I wouldn't think this should be necessary:
"In scalar context or if the left operand is not enclosed in
parentheses, it returns a string consisting of the left operand repeated
the number of times specified by the right operand."
Shouldn't the use of the '.' operator outside be sufficient to cause the
parenthetical part to be considered a scalar? Even if it's not, and the
bit inside the parens evaluates to a single-element list, I would still
expect to see:
1foo