in reply to private sub routine

This is an "anti-Perl" idea -> a wrong one. In Perl a sub name has "package" scope, usually, but not always one package "name space" per file.

In a function oriented package, the subs that are meant to be called by others are specified in the @EXPORT (), @EXPORT_OK() lines. In an OO module, you will see subs with names that begin with "_". Those are often names of methods (subroutines) that shouldn't be called by outsiders.

Basically, I suggest "play by the rules and get along with others". I think you are doomed to a life of unhappiness and pain if you insist that Perl work like your other language, which I am guessing is Java. On the plus side, a Perl program is often 1/10th or less than the size of a Java program, so there is less to keep track of!

Perl does allow you to "shoot yourself in the foot". If you provide a "fully qualified name", you can call that sub X in spite of naming and export conventions. I would say simply: "don't do that".

Replies are listed 'Best First'.
Re^2: private sub routine
by LanX (Saint) on Sep 03, 2009 at 00:05 UTC
    Funny, saranperl asks one of his overly condensed interview questions without any further explanation and he gets answers with desperate interpretations like in a interview.

    Is perlmonks an interview? Do we apply for a job?

    You're thinking of "private" like in Java and most of the others of "private" like in lexical variables.

    BTW: Googling for "private function" and "perl" quickly leads to perlmod

    # here's a file-private function as a closure, # callable as &$priv_func; it cannot be prototyped. my $priv_func = sub { # stuff goes here. };

    So why do we answer a question which can be easily resolved with googling???

    Cheers Rolf

      I didn't investigate saranperl's previous posts.
      Yes, there is a way to make a Perl "private sub".
      The part that wouldn't be resolved via Google is that this is a bad idea in Perl. Now that's my personal opinion, but I'm sticking to it and for good reasons.

        What makes it a bad idea?