in reply to multiple "sub" packages in 1 file: possible? how?

You have it almost right, but Perl needs to know which package things are coming from. Here's one way to do it:

use strict; package my_temp_convert; my $cur_ctemp=0; sub set_ctemp {$cur_ctemp = shift;} sub c {return $cur_ctemp;} sub f {return 32 + (9 * $cur_ctemp) / 5;} package main; my_temp_convert::set_ctemp(32); printf "%d F is %d C\n", my_temp_convert::f(), my_temp_convert::c();

Prints:

89 F is 32 C

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: multiple "sub" packages in 1 file: possible? how?
by perl-diddler (Chaplain) on Aug 05, 2007 at 03:14 UTC
    Yeah...I thought about explicit package names before the package names, but I wanted it to be as if I had "Exported" the names from the package (ala @Exports=qw(set_ctemp f c). Then I can use the "Exported" (from the inline package, in this case) names in the main program.