Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Input and Output > Output with say

Output with say

Perl 5.10 borrowed the say built-in from the ongoing development of Perl 6 (which may have borrowed its say from Pascal’s println). It’s the same as print, although it adds a newline to the end. These forms all output the same thing:

use 5.010;

print "Hello!\n";
print "Hello!", "\n";
say "Hello!";

To just print a variable’s value followed by a newline, I don’t need to create an extra string or print a list. I just say the variable. This is especially handy in the common case of simply wanting to put a newline after whatever I want to output:

use 5.010;

my $name = 'Fred';
print "$name\n";
print $name, "\n";
say $name;

To interpolate an array, I still need to quote it, though. It’s the quoting that puts the spaces between the elements:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint