perlquestion
Lexicon
<P>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?</P>
<P>In case it's a bug: I've run the following code on two machines:<BR>
This is perl, v5.8.5 built for i386-linux-thread-multi<BR>
This is perl, v5.8.6 built for darwin-thread-multi-2level<BR></P>
<readmore>
<code>
#!/usr/bin/perl
print (sort ( f( 0 ) ));
print (sort ( f ( 0 ) ));
print (sort ( &f ( 0 ) ));
print (sort f( 0 ) );
print (sort f ( 0 ) );
print (sort &f ( 0 ) );
sub f { 1 }
</code>
<P>And get the following results</P>
<code>
Chromium:~ lexicon$ perl -l little.pl
1
0
1
0
0
1
</code>
</readmore>
<P><B>Update:</B> 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 <tt>sort</tt> 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 [422132|no op unary + operator] which I had been using for years for subroutine calls as <tt>my %hash = %{+shift};</tt>. Although, really, <tt>sort &f(0)</tt> does the job and has the bonus of looking correct as well.</P>
<P><B>Update 2:</B> 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. <tt>print</tt> will try to call your function to get a file handle, for instance. </P>
<P>All the help is much appreciated, of course!</P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-37070">
<p><div align=center><b><A HREF="/index.pl?node=Lexicon&lastnode_id=1072">Lexicon</A></b></div>
</div></div>