Perl6 Cookbook

Ovid on 2005-04-09T20:13:22

Following autrijus' request for someone to create a pleac directory (basically, a Perl 6 Cookbook), I've started Pugs hacking. Here's examples/pleac/01strings/01-04converting-values.p6.

#!perl6

use v6;

# you want to convert characters to their numeric value or vice-versa
my $char = 'a';
my $num  = $char.ord;
say $num;
my $char2 = $num.chr;
say $char2;

$char = 'foo';
say $char.ord; # XXX is this correct behavior?

Every example I'm typing up is showing limitations with pugs, but they're also showing the power of pugs, too. I'm very impressed. Come join the fun! We need more folks hacking on the cookbook. Correct my Perl 6 code and write it in a more idiomatic style! Not, of course, that we've nailed down Perl 6 best practices yet, but I am trying to take advantage of Perl6 features rather than just cut-n-drool Perl 5 code.