Writing our Hello World program

So far, as we have installed the Rakudo Star compiler, it's now time to create the first program in Perl 6. It will print Hello, World! and exit.

The program is really easy. All you need is a single line with the only instruction to call the built-in say function. It takes the string, prints it to the console, and adds a new line after it.

This is how the whole program looks:

say 'Hello, World!'

Save the code to the file, say, hello.pl, and pass it to the compiler as follows:

$ perl6 hello.pl

It will compile the program and immediately execute it. The result is the desired string on the screen:

Hello, World!

Notice that the output ends with a new line. This is the behavior of the built-in say function. Alternatively, ...

Get Perl 6 Deep Dive now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.