note
Ven'Tatsu
<blockquote><i> This is not unlike just saying $x although they are not interchangable (don't as my why, I am still trying to grok details like this myself).</i></blockquote>
<p>There are two differences that I can see between <code>*$x</code> and <code>$x</code>. The first is parameter checking:</p>
<code>
sub fooprintf (*$fmt, *@args) { ... }
sub barprintf ($fmt, *@args) { ... }
$foramt = '%5d %10s';
@data = (16, "baz");
@both = ('%5d %10s', 16, "baz");
fooprintf($format, @data); #this works
fooprintf(@both); #so will this
barprintf($format, @data); #this works
barprintf(@both); #this won't work
barprintf(*@both); #but this will
</code>
<p><code>fooprintf</code> will take any LIST of arguments and will just trust you the the first item in the (flatened) list is a scalar, while <code>barprintf</code> will force you to give it a scalar as it's first argument, or force you to flaten any arguments you pass it your self. In some cases this could catch at compile time errors that Perl5 would not have caught until runtime. (can you see the uncaught error in <code>printf $format @data</code> or the reverse <code>printf $filehandle, @both</code>?)</p>
<p>The other issue is context, ponder these:</p>
<code>
fooprintf(localtime); #localtime is called in array context
barprintf(localtime); #localtime is called in scalar context
</code>
<p>If your intent was to print out the current seconds then the <code>fooprintf</code> will work, if however you were looking for the strigified representation of the current time <code>barprintf</code> is will likely be closer to what you expected.</p>
434972
435074