On 11/17/09 Tue  Nov 17, 2009  9:24 AM, "Parag Kalra" <paragka...@gmail.com>
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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to