Re: Redirect Print
[email protected] (Paul Lalli)
| Newsgroups | perl.beginners.cgi |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <[email protected]> |
On May 30, 11:56 am, [email protected] (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...