in reply to Re^2: multiple "sub" packages in 1 file: possible? how?
in thread multiple "sub" packages in 1 file: possible? how?
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' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: multiple "sub" packages in 1 file: possible? how?
by chromatic (Archbishop) on Aug 05, 2007 at 06:45 UTC | |
by naikonta (Curate) on Aug 05, 2007 at 07:09 UTC | |
by chromatic (Archbishop) on Aug 05, 2007 at 20:56 UTC |