in reply to Re: Using "USE" instead of "DO" for subroutines call in external file
in thread Using "USE" instead of "DO" for subroutines call in external file

thanks. but I tried your solution by putting "1;" at the end of mysub.pm. But it still fails, same error message.
sub mysub1{ # somecodes } sub mysub2{ # somecodes } 1;
"happens at runtime" is slower than "compile time" ?
  • Comment on Re^2: Using "USE" instead of "DO" for subroutines call in external file
  • Download Code

Replies are listed 'Best First'.
Re^3: Using "USE" instead of "DO" for subroutines call in external file
by Zaxo (Archbishop) on May 27, 2005 at 07:23 UTC

    I just noticed your use syntax, say

    use mysub; # not # use mysub.pm;
    to load the module. I see a syntax error for that, rather than not returning true, though.

    Your example works for me.

    After Compline,
    Zaxo

      thanks a million. It works fine now. However, timing the two instances "do" versus "use", seems that 'do' is faster: with "use":
      1.01user 0.01system 0:01.09elapsed 94%CPU
      with "do":
      0.94user 0.01system 0:01.03elapsed 93%CPU
      Would you suggest I stick to "do"?

        I think you should worry less about speed. The numbers you show are not a significant time difference for a statement which will only run once in a non-trivial program. Particularly not for a disk I/O operation which may be influenced that much by head position or system traffic.

        A better criterion is to consider how soon your program should know about your subs. By loading at compile time with use, perl knows the location and properties of your subs at compile time. With that, for instance, subs prototypes become effective, where they would be ignored if loaded at runtime. That may even gain you some speed at runtime.

        Note: Don't go stick prototypes on everything! They're much misunderstood and rarely necessary.

        After Compline,
        Zaxo