Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Possible to have a module act as a standalone??

by dragonchild (Archbishop)
on Mar 18, 2003 at 16:46 UTC ( #244164=note: print w/replies, xml ) Need Help??


in reply to Possible to have a module act as a standalone??

You're thinking about the problem wrong. A module isn't anything more than a collection of (possibly) related functions (and maybe some data). Perl doesn't actually have support for "modules", per se. There are packages and there are files. Most of the time, the "One package, one file" rule tends to hold, so those things are often called modules.

What I understand you wanting to do is to have a set of functionality that can return its output in 2 different ways. Ok - have the functions in the module accept a flag that determines what it should do with that data.

Then, you have your CLI thingy do its thing and you have a stand-alone script that does its thing. (The stand-alone script will, most likely, be extremely short, but that's a good thing.)

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

  • Comment on Re: Possible to have a module act as a standalone??

Replies are listed 'Best First'.
Re: Re: Possible to have a module act as a standalone??
by rjray (Chaplain) on Mar 18, 2003 at 17:51 UTC

    Hmmm... I read this as him wanting a way to write, say, Npid.pm (for lack of a better name) such that a script can "use Npid;" and the right thing happens, but he can also do (from the command-line) "perl Npid.pm" and the right thing also happens.

    --rjray

      You're correct - that was the actual question. The question presupposes an incorrect analysis of whatever problem he's attempting to solve. I could've given him an answer to his problem (cause this is a do-able thing), but he would not have grown as a programmer. The analysis of the problem was wrong. Ultimately, that is a goal of PerlMonks. (At least, that's how I've come to see this community.)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

        well, aren't you the smug one? Not.
        Tell me, you've bought one of those shirts from thinkgeek that says "No I will NOT fix your computer!", right?
        Or do you instead have as a role model the bureaucrats at the local DMV who will refuse service if one has marked initials in box 37-c while smugly pointing out that signatures are required in 37-c while initials are required in 37-d? geez, monks like you make me sick. What I would like to see in a community is friendly help:
        "Hey, I'm thinking of doing this. I'm going to use module X and Y."
        "Well, ok, but I think you'd be better off with module A. Here's why..."

        --
        We are the janitors of the Information Age.
        Oh, and please remember I'm a jerk. Don't take it personally.
Re: Re: Possible to have a module act as a standalone??
by Anonymous Monk on Mar 18, 2003 at 19:48 UTC
    Whoa there. It sounds like he's trying to do what they do in java /w main()

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://244164]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2019-07-24 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (32 votes). Check out past polls.

    Notices?