[EMAIL PROTECTED] wrote:
Hi,

I have some subroutine that tests either one machine or a bunch of them. If
it's a single machine, the "print" statements in the subroutine should go to
stdout (no change needed for this, that's how it works now), if however I
want to test a lot of machines, I want the "print" statements redirected to
a logfile.

from a "logical" thought something like this:

if ($opt_l) {
	open Logfile;
	$print=LOG;
}

sub test {
	print $print "some output";
}

so if $print is empty it prints to stdout, if it contains LOG it should do a
"print LOG 'some output';".

somehow my logic doesn't work though, what's the correct way?
Try using a ref to your FH:

my $print = \*STDOUT;
if ($opt_l) {
	open LOG, ">Logfile";
	$print = \*LOG;
}

test ();

sub test {
print $print "some output\n";
}

__END__



--
  ,-/-  __      _  _         $Bill Luebkert   ICQ=162126130
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@;todbe.com
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to