The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
Different Between "Print" and "Print STDERR"
Discuss Different Between "Print" and "Print STDERR" in the Perl Programming forum on Dev Shed. Different Between "Print" and "Print STDERR" Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 8th, 2013, 02:07 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 6
Time spent in forums: 19 m 29 sec
Reputation Power: 0
|
|
|
Different Between "Print" and "Print STDERR"
Hi, COuld you explain to me with example what is the different between "Print" and "Print STDERR".When to use "Print STDERR"?Wny use "Print STDERR" instead of "PRINT" in perl.
|

January 8th, 2013, 03:52 AM
|
 |
kill 9, $$;
|
|
Join Date: Sep 2001
Location: Shanghai, An tSín
|
|
By default, Perl's 'print' function will print to Standard Output (STDOUT). If you want to print to any other filehandle (including Standard Error (STDERR)), you have to specify it when you call 'print'. Incidentally, the function is called 'print', not 'Print'. Perl is case sensitive.
To read about the differences between STDOUT and STDERR, have a look here.
|

January 8th, 2013, 08:04 AM
|
|
|
Personally, I prefer to use the warn function instead of the print function when I want to send output to STDERR.
perldoc -f warn
|

January 8th, 2013, 04:12 PM
|
|
|
Quote: | Originally Posted by FishMonger Personally, I prefer to use the warn function instead of the print function when I want to send output to STDERR. |
Yes, or possibly the die function, if the error should be considered to be fatal.
|

January 8th, 2013, 04:35 PM
|
|
|
Quote: | Originally Posted by Laurent_R Yes, or possibly the die function, if the error should be considered to be fatal. |
Or, if we really want to follow the current best practices, use the carp, croak, cluck, and confess functions from the Carp module.
use Carp;
Quote: carp - warn of errors (from perspective of caller)
cluck - warn of errors with stack backtrace (not exported by default)
croak - die of errors (from perspective of caller)
confess - die of errors with stack backtrace |
|

January 8th, 2013, 09:03 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 6
Time spent in forums: 19 m 29 sec
Reputation Power: 0
|
|
|
Thx for you guys information.
|

January 9th, 2013, 01:26 AM
|
|
|
Quote: | Originally Posted by FishMonger Or, if we really want to follow the current best practices, use the carp, croak, cluck, and confess functions from the Carp module.
use Carp; |
Yes, I thought about Carp when I wrote the previous message.
There is one thing I really dislike about this module, though: whoever wrote it should have chosen function names that make sense to non native English speakers.
Assuming I am new to Perl, if I see "warn" or "die" in a program I can pretty well guess what it does. But carp, cluck or even croak, I just can't guess.
|

January 9th, 2013, 08:15 AM
|
|
|
Quote: There is one thing I really dislike about this module, though: whoever wrote it should have chosen function names that make sense to non native English speakers.
Assuming I am new to Perl, if I see "warn" or "die" in a program I can pretty well guess what it does. But carp, cluck or even croak, I just can't guess. |
I completely agree. I often need to look them up because I keep forgetting which one does what I need at any given point.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|