Matt Diephouse wrote:
Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]> wrote:Certainly. Almost anywhere you can use an array, an array ref will do instead.
Besides, I think "as" will do just fine, especially since you can now interpolate method calls as well. You can even do something like this if you want to perform bulk formatting:
say join ' ', ($n1, $n2, $n3) >>.as('%d');
What about:
say [ $n1, $n2, $n3 >>.as('%d') ].join;
?
Can I (1) use join on a bracketed list
and (2) leave off theI think you'd need the parens there, to distinguish that the . operator applies to the list, not to $n3. Hyper's are not on the list because they are adverbs to the existing operators. In this case, you're using unary ., so you follow it's precedence.
parentheses around C<$n1, $n2, $n3>? (I couldn't find where hyper ops
are on the precedence table.)
You could easily write the above as
say (($n1, $n2, $n3)».as('%d')).join;
What I'm not certain about is if
say ($n1, $n2, $n3)».as('%d').join;
does the same thing, but I think it does.
No. .key returns a string, which you call the .as method of, which is fine, but the .value is a separate expression, and references the current topic, which is not tied to the array.And this:
say [ $num => '%d', $str => '%s' ] >>.key.as(.value);
Related to what I'm not sure about above is that I think you'd have to say C< [...]».key».as($pattern) > to get it working correctly.
Yes, but whitespace between the "say" and "(" should do the trick as well. Might generate a warning, however.(4) use square brackets in this instance (to make sure my list doesn't form a parameter list to C<say>)?
-- Rod Adams