So is there anyway to define a separately named package and not put it in another file? How do I "use" it in the main scriptlet file? Don't focus on the triviality of my "temperature convert" package -- it's just to demonstrate what I'm talking about. In case anyone wonders why I would do such a thing 0 -- it's a program in "development" -- I might eventually break up separate packages into separate files if they are complex enough and "standalone", but for now, it's just a way of separating the "sub package" code from the main code. I may also want to use sub packages to create objects as I abstract the code more... Thanks for any insights.......prog....(main)....(statements in package main here).. use strict; use Readonly; ...then a package definition in middle of prog.... package my_temp_convert; our $VERSION = '.01'; require Exporter; our @ISA = ('Exporter'); our @EXPORT = qw(set_temp, set_scale, c, f); my curr_scale=0; #centigrade, 1=faren my cur_ctemp=0; sub set_scale{ curr_scale=shift} sub set_temp($){#convert to C if needed, and store in "curtmp"} sub c {return cur_temp;} sub f {return 32+(9*cur_temp)/5} #now back to main.... package main; # somehow "use the above, inline package, "temp_convert"; set_scale(1); set_temp(32); print "%d F is %d C\n", f(), c(); #prints "32 F is 0 C" #end prog
In reply to multiple "sub" packages in 1 file: possible? how? by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |