Print ‘Hello, World!’
There are two built-in functions in Perl 6 to print to the console: printand say. Both print their arguments, but the
say routine additionally ends the output with a newline character.
So, the quickest solution is to use sayand pass a string with no newlines:
say 'Hello, World!'
Another solution is to use
\n character in the string itself:
print "Hello, World!\n"
The output of either program is the same:
Notice the difference between single and double quotes: single quotes do not interpolate special characters like
\n while the double quotes do. There’s no mistake in using double quotes for strings without special characters, while it is better to use the appropriate quoting style when you do not expect variables in the string and when there is no need to interpolate variables.Another thing to take a look at in the examples above is that a semicolon is not required for one-line programs.