📘 How to debug Perl 6 programs

📘 How to debug Raku programs

N. B. Perl 6 has been renamed to Raku. Click to read more.


For quick tests, use the compiler in the mode of the REPL (read—eval—print loop) shell. Just run the perl6 command:

$ perl6
To exit type 'exit' or '^D'

With bigger programs, one of the following techniques helps to visualise data:

1. The say routine is used as a stand-alone function or as an object method. It works well with both scalar and aggregate data, such as arrays, hashes, or objects:

say $x;
%data.say;

2. The perl method, which returns the representation of an object in the Perl 6 syntax:

say {a => 1, b => 2}.perl; # {:a(1), :b(2)}

3. The WHAT and the ^name methods, which give you the information about the object type or class name:

my Int $x;
say $x.WHAT;  # (Int)
say $x.^name; # Int

4. The dd routine. This is a Rakudo-specific feature that dumps an object:

my @a = 1..5;
dd @a; # Array @a = [1, 2, 3, 4, 5]

One thought on “📘 How to debug Perl 6 programs”

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code