On 11/17/09 Tue Nov 17, 2009 9:24 AM, "Parag Kalra" <[email protected]>
scribbled:
> Hi All,
>
> I know this may be a very basic question but I don't know how to accomplish
> it. :(
>
> I want to know how to redirect a message simultaneously to a file-handler
> and standard O/P.
>
> So basically I want a short cut way to execute following 2 commands using
> one singe command which will print the message both into file handler and on
> the console:
>
> print $message;
> print FILE, $message;
You write a subroutine:
my_print
{
print "@_";
print FILE "@_";
}
and call it:
my_print($message);
You may want to choose a different way of treating multiple arguments.
You are looking here for what is sometimes called a "logger". There are Perl
modules on CPAN that may be of interest, such as Log::Dispatch or
Log::Log4Perl. Search the Log hierarchy for more. (I haven't used any of
them, so can't recommend any particular one.)
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/