πŸ“˜ Hello, World! in Perl 6

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 print and include the \n character in the string itself:

print "Hello, World!\n"

The output of either program is the same:

Hello, World!

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.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s