Actually this is a really cool trick
Indeed. I use the return value in list form often (in fact, the code in my original post uses that technique), and it is a useful feature. There are many cases where it is much nicer than the alternatives. That is beside the point, though. The point is, hardburn showed a nifty feature that is somewhat similar, but not quite. I just wanted to explain why it was not quite the same.
hashes (as nice as they are), do not interpolate
Sure, you can't dump the entire hash contents as easily as you can with an array, but individual hash elements interpolate just fine:
my %hash = (one => 1, two => 2);
print "$hash{one}\n";
And if you really want the entire hash contents, you can use the array dereference interpolation trick:
print "@{[ %hash ]}\n";
This trick can be used to interpolate arbitrary code, as long as the ultimate return value is an array reference. It is fairly ugly, though, and usually avoided. Here's a simple demonstration:
print "@{ for (1 .. 2) { print qq(Hi!\n); } [ qq(Bye!\n) ]}";
|