in reply to Trouble usig a subroutine from a custom module

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^2: Trouble usig a subroutine from a custom module
by choroba (Cardinal) on Nov 09, 2024 at 10:09 UTC
    1. You can replace the eval abomination with a single call to do.
    2. But with eval and not checking its return value, you have no idea whether there was an error in the module. You can drivel about its advantages and disadvantages (see your points 3, 3b, and 3c), but especially given the "new job" requirement, I'd be very cautious throwing around dangerous advice.
    3. Re 4: You can add code to a normal module and it will run when the module is first used or required.
    4. You should read about scope in Perl. Lexical variables aren't accessible outside of their scope.
    5. Re 7: Who told you Perl changed the way it interprets prototypes? Why do you need to include FUD into your post?
    6. Why are you using a bold font? It looks like speaking very loudly, which is impolite and disrespectful.

    Update: I know what we're talking about. I posted Wrong + Right = Even Worse 10 years ago.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: Trouble usig a subroutine from a custom module
by jo37 (Curate) on Nov 09, 2024 at 09:30 UTC

    Ever heard of do?

    Greetings,
    🐻

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
Re^2: Trouble usig a subroutine from a custom module
by soonix (Chancellor) on Nov 09, 2024 at 14:55 UTC
    • I second unbolding your post. It is good that you name disadvantages and vulnerabilities, but bold should be used sparingly.
    • choroba already commented on several of your points
    • 2: instead of calling it a "module that isn't really a module", you could call it a "snippet", or a "paste".
    • 3c: the execute bit is not relevant in this context (it doesn't prevent reading, that's what read permission is for) The execute bit would allow for a standalone script with shebang to be called directly without explicitly calling perl[.exe]
    • 5: I myself have a snippet that defines π via
      use constant PI => atan2(0, -1);
      (which has other disadvantages)
      The non-accessibility of $PI in your case is because it is defined within eval.
    • reading a complete file was just recently discussed in e.g. Re^3: Entity statistics. (I like Path::Tiny)
Re^2: Trouble usig a subroutine from a custom module
by LanX (Saint) on Nov 09, 2024 at 12:46 UTC
    > Somebody please correct me. :P

    Unfortunately your "bold" answer is unreadable.

    (Or fortunately, regarding choroba's answer...?)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    A reply falls below the community's threshold of quality. You may see it by logging in.