Re: Coderefs in objects: tricky questions



peterkayatwork@xxxxxxxxx wrote:

3.  Is there a way to set $self->{Sub} without using 'sub'?

I want to pull this effect off:

$self->{Sub} = sub { return $self->Real(@_) };

without using 'sub'.

Why? A coderef is created using 'sub'. A coderef is executed by invoking it as a function. Assuming you could create a coderef without 'sub', it would still have to be invoked as a subroutine/function to get executed.

Besides, can't I claim that the "sub" adds another layer of
subroutines, thus hurting the execution time of my script?

No. You have to go through internal process of pushing things onto the call stack to execute the code; so there is no getting around that bit of overhead. -Joe .



Relevant Pages

  • Re: Optimize my script
    ... When I run with "./analyze.pl foo bar" the execution time is fast, ... I'm not very familiar with the profiler, but at a guess, I would say ... that the profiler only counts time in subroutines, ... to gain a finer grained but less accurate profiling report ...
    (perl.beginners)
  • Re: subroutine execution speed
    ... The NI documentation says that subroutines get a minimised overhead ... The execution performance of subroutines cannot be reached by ... placing this VI in a for loop (select N so, that the loop executes for a few seconds) ... check the overall execution time for different VI priorities. ...
    (comp.lang.labview)
  • Re: perl script execution take a long time
    ... I am having a perl script.The main script calls some 10 subroutines ... Please tell me the way to reduce the execution time. ... Posting complete working code that illustrates your problem will be especially helpful in getting your problem solved. ...
    (comp.lang.perl.misc)
  • Re: perl script execution take a long time
    ... g> I am having a perl script.The main script calls some 10 subroutines ... g> Please tell me the way to reduce the execution time. ...
    (comp.lang.perl.misc)