Keep It Simple, Stupid | |
PerlMonks |
<> and <ARGV> are the same thing, except when they aren'tby Porculus (Hermit) |
on Sep 17, 2009 at 20:22 UTC ( [id://795969]=perlmeditation: print w/replies, xml ) | Need Help?? |
Making cosmetic changes in the presence of magic is rarely advisable. So I suppose I shouldn't have been surprised when changing <ARGV> to <> broke a working script. The context here is the dumping of all input to a temporary file:
This works. But changing the second line to print $fh <>;causes it to fail with the message "syntax error ... near <>". This puzzled me for a long time. Surely <> and <ARGV> are synonyms? Why would one work and the other fail? <Reveal this spoiler or all in this thread>
For about five minutes after this dawned on me, I wished that Perl had just a little more magic in it, so that my change wouldn't have broken anything. But then I realised that adding more magic would just make the cases where it doesn't DWIM even more unexpected and confusing. I note in passing that Perl 6 will use a less ambiguous syntax that won't break this way. Which I like, even though it looks a bit ugly to me at the moment. I want the experience of programming to be magical, not the syntax.
Back to
Meditations
|
|