That's not dying though. It's giving a warning. And the warning isn't about the fact the key doesn't exist it's about using the returned undefined value in the string interpolation.
– ScimonJan 22 at 17:23

The fatal pragma makes returning a Failure from a routine automatically throw an exception that contains the Failure. Unless you provide code that catches them, these exceptions that wrap Failures automatically die.

Use either Jonathan++'s answer (use put, which, unlike say, isn't trying to keep your program alive) or Scimon++'s KeyRequired answer which will make accessing of a non-existent key fatal.

... as Perl5 does ...

Only if you use use warnings 'FATAL' ..., just as P6 does if you use the equivalent.

... because this implies that important data is missing.

Often it implies unimportant data is missing, or even important data that you don't want defined some of the time you attempt to access it, so Perls default to keeping your program alive and require that you tell it what you want if you want something different.

You can use the above constructs to get the precise result you want and they'll be limited to a given variable (if you use the KeyRequired role) or statement (using put instead of say) or lexical scope (using a pragma or the CONTROL block).

Perl 5 warns, not dies, in this case. Perl 6 will do the same if equivalent code is used:

my %key;
print "%key<fake_key>\n"; # Gives a warning

Or, more neatly, use put:

my %key;
put %key<fake_key>;

The put routine ("print using terminator") will stringify the value, which is what triggers the warning about use of an undefined value in string context.

By contrast, say does not stringify, but instead calls .gist on the object, and prints whatever it returns. In the case of an undefined value, the gist of it is the name of its type, wrapped in parentheses. In general, say - which uses .gist underneath - gives more information. For example, consider an array:

my @a = 1..5;
put @a; # 1 2 3 4 5
say @a; # [1 2 3 4 5]

Where put just joins the elements with spaces, but say represents the structure and that it's an array.

thanks, put is definitely useful, I'm surprised that I don't see it more often in the documentation. I'm looking for the perl6 equivalent of use warnings 'FATAL' => 'all'; use autodie qw(:all); this is close stackoverflow.com/questions/34747960/… but it will still miss errors
– conJan 22 at 17:59

say %key<fake_key>;
# (Any)
put %key<fake_key>;
# Use of uninitialized value of type Any in string context.
# Methods .^name, .perl, .gist, or .say can be used to stringify it to something
# meaningful.
# in block <unit> at <unknown file> line 1

say calls .gist which prints enough information for a human to understand what was printed.put just tries to turn it into a Str and print that, but in this case it produces an error.