Well, this works too, if you really want to go through Exporter. I don't think you're going to be able to use as you would if the package were in a separate file since use really implies other fileness.
use strict; use warnings; use Test::More 'no_plan'; package my_temp_convert; 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{ $cur_ctemp =shift} sub c {return $cur_ctemp;} sub f {return 32+(9*$cur_ctemp)/5} package main; Exporter::import( 'my_temp_convert' ); set_scale(1); set_temp(0); is( f(), 32, 'f() returns 32' ); is( c(), 0, 'c() returns 0' );
In reply to Re^3: multiple "sub" packages in 1 file: possible? how?
by kyle
in thread multiple "sub" packages in 1 file: possible? how?
by perl-diddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |