Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Unexpected difference in whitespace parsing in subroutine calls.by Lexicon (Chaplain) |
on Jul 10, 2005 at 09:02 UTC ( [id://473740]=perlquestion: print w/replies, xml ) | Need Help?? |
Lexicon has asked for the wisdom of the Perl Monks concerning the following question: There seems to be a difference in the parsing if you put whitespace in between a subroutine name and the subroutine parameters. I imagine this is known, and probably even documented somewhere, but I haven't been able to find it. Can anyone explain the difference? In case it's a bug: I've run the following code on two machines:
And get the following results
Update: No offense guys, but you should read the existing comments before replying to a thread. broquaint had already subtly clued me in that f gets called as the sort subroutine in some cases and noth others. I still find the difference surprising, but etcshadow addressed it as just one of those "crazy rules" perl has for ambiguous situations. etcshadow also pointed out the no op unary + operator which I had been using for years for subroutine calls as my %hash = %{+shift};. Although, really, sort &f(0) does the job and has the bonus of looking correct as well. Update 2: I thought I should also mention, to those who aren't aware, that this will apply to a lot of situations with built in functions. print will try to call your function to get a file handle, for instance. All the help is much appreciated, of course!
Back to
Seekers of Perl Wisdom
|
|