We're talking about symbolic references here

Yes and no.

Yes, Perl looks up methods in the symbol table when you dispatch to them.

No, it does this for methods anyway. If you write a small test program:

use CGI; my $q = CGI->new(); my $new = 'new'; my $z = CGI->$new();

and dump the optree:

$ perl -MO=Concise method_dispatch.pl l <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 514 method_dispatch.pl:8) v/2 ->3 8 <2> sassign vKS/2 ->9 6 <1> entersub[t2] sKS/TARG,2 ->7 3 <0> pushmark s ->4 4 <$> const(PV "CGI") sM/BARE ->5 5 <$> method_named(PVIV "new") s ->6 7 <0> padsv[$q:514,517] sRM*/LVINTRO ->8 9 <;> nextstate(main 515 method_dispatch.pl:9) v/2 ->a c <2> sassign vKS/2 ->d a <$> const(PV "new") s ->b b <0> padsv[$new:515,517] sRM*/LVINTRO ->c d <;> nextstate(main 516 method_dispatch.pl:10) v/2 ->e k <2> sassign vKS/2 ->l i <1> entersub[t5] sKS/TARG,2 ->j e <0> pushmark s ->f f <$> const(PV "CGI") sM/BARE ->g h <1> method sK/1 ->i g <0> padsv[$new:515,517] s ->h j <0> padsv[$z:516,517] sRM*/LVINTRO ->k method_dispatch.pl syntax OK

you'll see that the effective difference is in the method_named and method ops. Looking in pp_hot.c, the former calls method_common with the SV containing the name of the method. The latter checks that the child SV is a reference and returns it if so or calls method_common otherwise.

method_common looks up the method in the appropriate stash and returns the reference.

Is there a difference? I don't really see one. Besides all this, Perl doesn't (and often can't) resolve the target of method calls statically anyway. (There might be some post hoc ergo propter hoc somewhere in all of this.)


In reply to Re: Need help with a conceptual speed bump by chromatic
in thread Need help with a conceptual speed bump by mstone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.