Home > Archive > PERL CGI Beginners > July 2007 > Redirect Print
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Khalid Naji 2007-05-30, 9:55 pm |
| Hi,
is there any way to mask a printing, when I call a Function using the
Command "print" and without to modify this Function:
Like:
My ($Name) =3D &get_name(12345);
Sub get_name
{
$id =3D @_;
....
Print "Blalalalalalalbla...\n";
Return (Name);
}
Thanks,
KN
| |
| Sean Davis 2007-05-30, 9:55 pm |
| On Wednesday 30 May 2007 11:56, Naji, Khalid wrote:
> Hi,
>
> is there any way to mask a printing, when I call a Function using the
> Command "print" and without to modify this Function:
>
> Like:
>
> My ($Name) = &get_name(12345);
>
> Sub get_name
> {
> $id = @_;
> ...
> Print "Blalalalalalalbla...\n";
> Return (Name);
> }
Printing will go to stdout, which is then sent to the browser. If you don't
want that to go to the browser, you can print to STDERR and that will
typically end up in the error_log file for your server.
Sean
| |
| Paul Lalli 2007-05-30, 9:55 pm |
| On May 30, 11:56 am, Khalid.N...@bsz-bw.de (Khalid Naji) wrote:
> is there any way to mask a printing, when I call a Function using the
> Command "print" and without to modify this Function:
>
> Like:
>
> My ($Name) = &get_name(12345);
>
> Sub get_name
> {
> $id = @_;
> ...
> Print "Blalalalalalalbla...\n";
> Return (Name);
>
> }
You can open a filehandle to the system's /dev/null and then select
that filehandle to make it the default. Make sure you reselect the
original filehandle when the subroutine is done. For example:
$ perl -le'
print "Start";
open my $devnull, ">", "/dev/null" or die $!;
my $old_fh = select $devnull;
mysub();
select $old_fh;
print "End";
sub mysub {
print "In mysub";
}
'
Output:
Start
End
Paul Lalli
P.S. Please don't use a word processor to compose a post to a
technical list/newsgroup. Or at the very least, turn off the word
processor's auto-capitalization feature. You make it impossible for
anyone to copy and paste your code...
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|