subref.pl to HTML.

index -|- end

Generated: Tue Feb 2 17:54:57 2010 from subref.pl 2008/02/13 800.

#!/perl -w
# NAME: subref.pl
# AIM: To call a function, or set a global, by calling a function ...
use strict;
use warnings;
my $value1 = "<1 not set>";
my $value2 = "<2 not set>";
my ($valref, $serv);
sub set_value1 { $value1 = shift; }
sub set_value2 { $value2 = shift; }
sub type1 {
   my ($msg) = shift;
   prt( "Run TYPE1 ... $msg ...\n" );
}
sub type2 {
   my ($msg) = shift;
   prt( "Run TYPE2 ... $msg ...\n" );
}
my $test = 1;
if ($test == 1) {
   $serv = \&type1;
   $valref = \&set_value1;
} else {
   $serv = \&type2;
   $valref = \&set_value2;
}
$serv->( "This msg" );   # call the 'service', with value
$valref->( "IS SET" );   # set a global, with this value
prt( "value1 = $value1, value2 = $value2 ...\n" );
sub prt {
   my ($t) = shift;
   print $t;
}
# eof - subref.pl

index -|- top

checked by tidy  Valid HTML 4.01 Transitional