Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: routine as subroutine and on command line

by count0 (Friar)
on Jan 18, 2002 at 19:39 UTC ( #139836=note: print w/ replies, xml ) Need Help??


in reply to routine as subroutine and on command line

It sounds like you're crying out for modules (or better, object classes ;)

If you need to be calling only certain subroutines from the command line, this is the ideal (imo) way to go.
Instead of avg_routines.pl, make it AvgRoutines.pm. This will also require changing parts of it (adding a 'package' line to the top, at least) to turn it into its own package.

Here's a simple example:

package AvgRoutines; sub avg3 { # ... code ... } 1;
See Simple Module Tutorial for a simple introduction to modules, if you need it. For a more technical primer, see perlmod.

Now, with it being its own module you can call just the sub you need from the command line *or* from other scripts (by use'ing it).

cat some_file_holding3numbers.txt | perl -I'.' -MAvgRoutines -pe 'AvgRoutines::avg3($_)' > avg.txt
See perlrun for any help with those command line switches.


Comment on Re: routine as subroutine and on command line
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (18)
As of 2014-08-28 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (261 votes), past polls