Says YuckFoo:
It never made sense to me why no commas are allowed after the filehandle in a printf with parentheses. I think even
if someone could explain why printf(OUT "foo\n"); is the reasonable or logical choice, I would still not be satisfied.
It's not just the reasonable, logical choice, it's pretty much the only
choice. If there were a comma after the filehandle, then
what would this do?
print $x, $y;
Are you printing the contents of $y to filehandle $x?
Or are you printing the contents of $x and $y
to stdout?
This is the same old problem that you always have when there's an optional argument
at the beginning of an argument list instead of at the end:
How do you tell if the optional argument is there or not?
Sometimes external factors allow you to tell; when there are no
such external factors, you have to invent a syntactic distinction.
--
Mark Dominus
Perl Paraphernalia
| [reply] [d/l] |
See, it almost makes sense, but I'm not satisfied.
If there were a comma after the filehandle, then what would this do?
print $x, $y;
Are you printing the contents of $y to filehandle $x? Or are you printing the contents of $x
and $y to stdout?
If $x is a filehandle, of course I am printing contents of
$y to filehandle $x.
Your other alternative is a non-alternative. If $x is a filehandle,
print $x, $y; doesn't print contents of $x and $y to STDOUT, it
generates error 'No comma allowed after filehandle...'.
So if it's not really a choice, why not 'do the right thing'.
If Perl is smart enough to know it's a filehandle, why isn't
it smart enough to use it as such?
YuckFoo
| [reply] |
$x = 'STDERR';
$y = "I like pie.\n"
print $x, $y;
Now what?
--
Mark Dominus
Perl Paraphernalia
| [reply] [d/l] |