Nov 17, 2009 5:32 pm
Jim GibsonOn 11/17/09 Tue Nov 17, 2009 9:24 AM, "Parag Kalra" <paragkalra@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;
>
> 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.)
Nov 17, 2009 5:24 pm
Parag Kalra--0016e64b99f48f1e590478946599
Content-Type: text/plain; charset=UTF-8
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;
Cheers,
Parag
--0016e64b99f48f1e590478946599--
Nov 17, 2009 7:46 pm
MattOn Nov 17, 12:32?pm, jimsgib...@gmail.com (Jim Gibson) wrote:
> On 11/17/09 Tue ?Nov 17, 2009 ?9:24 AM, "Parag Kalra" <paragka...@gmail.com>
> scribbled:
>
> 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.)
> scribbled:
>
> > Hi All,
>> > I know this may be a very basic question but I don't know how to accomplish
> > it. :(
>> > it. :(
> > I want to know how to redirect a message simultaneously to a file-handler
> > and standard O/P.
>> > 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:
>> > one singe command which will print the message both into file handler and on
> > the console:
> > print $message;
> > print FILE, $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.)
http://search.cpan.org/~dagolden/Tee-0.13/lib/Tee.pod
Previous Thread: How to complete the loop while debugging.
Next Thread: Is it necessary to open the file again to read its contents.
Related Forum Topics
- Redirect Find::File to /dev/null
- What's a database handler
- Text-html from file to a message body
- RE: Non standard entity conversion
- LWP module part of the standard distribution ?
- Mechanize Redirect
- Redirect option
- Redirect STDERR
- How to do absolute redirect in perl
- How to redirect in system command two devices at once