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:
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.
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:
See Simple Module Tutorial for a simple introduction to modules, if you need it. For a more technical primer, see perlmod.package AvgRoutines; sub avg3 { # ... code ... } 1;
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.
|
---|
In Section
Seekers of Perl Wisdom