Auto print a new line in Perl

In Perl, just have print function, where is the println func. similarly in C++ ? Perl doesn’t have one! Help!

google: perl println ->
perl.com: Perl’s Special Variables

From there they show us to make it available by adding our own function :

  sub println {
local $\ = "\n";
print @_;
}

The main idea is $\ is a special system variable that auto add to the end of the string printed by command print.
Since then, enjoy the convenient from : println "Ur text goes…" !

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: