How to print a line to STDERR and STDOUT in Perl?

In Perl, how to print a string as a line to STDOUT? That is, the string and the newline character, nicely?

And similarly, how to print the line to STDERR?

asked Jun 5 by dtivl (2,500 points)

1 Answer

In Perl, to nicely print a new line to STDOUT, you can use the "say" feature which "Just like print, but implicitly appends a newline":

use 5.010;
say "hello world!"

An example,

$ perl -de1

main::(-e:1):	1
  DB<1> use 5.010;

  DB<2> say "hello world"
hello world

  DB<3> 

In Perl, to print to STDERR, you can print to STDERR which is the STDERR:

say STDERR "your message here"

For example,

$ perl -de1

main::(-e:1):	1
  DB<1> use 5.010;

  DB<2> say STDERR "hello world";
hello world

  DB<3> 
answered Jun 5 by dtivl (2,500 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...