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
|
|---|
| 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 |