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”