#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep 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.
  2. #2
  3. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,898
    Rep Power
    3887
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,941
    Rep Power
    1225
    Personally, I prefer to use the warn function instead of the print function when I want to send output to STDERR.

    perldoc -f warn
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,941
    Rep Power
    1225
    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;

    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
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0
    Thx for you guys information.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    837
    Rep Power
    496
    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.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,941
    Rep Power
    1225
    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.

IMN logo majestic logo threadwatch logo seochat tools logo