In Perl5, I might write:
sub set_date {
my ($self, $date) = @_;
$date =~ /(\d{4})-(\d{2})-(\d{2})/ or croak "bad date format";
@$self{qw/year month day/} = ($1,$2,$3);
}
I could then call:
$foo->set_date('2002-09-04')
In Perl6 I can write:
sub set_date ( $date is rx/<iso_date>/ )
{
($.year, $.month, $.day) = $date{qw/year month day/}
}
(aside: is this the correct syntax for a Perl6 hashref slice? Could I use
%date instead of $date as my match object?)
Anyway, ignoring the syntax errors, I think I have some valid Perl6 here. I
could now write:
$foo.set_date 2002-09-04;
But can I use a non-constant date?
Perl5: $day = "04"; $foo->set_date("2002-09-$day");
Perl6: $day = "04"; $foo.set_date 2002-09-$day; # ERROR -- doesn't match
regex
Perl6: $day = "04"; eval "\$foo.set_date 2002-09-$day"; # clunky
Obviously we could put the onus on the module writer to write super-flexible
rules/grammars. But will there be an easy way to force interpolative context
onto this type of regex-valued subroutine arg?
Eagerly awaiting A6,
Dave.
--
Dave Whipp, Senior Verification Engineer,
Fast-Chip inc., 950 Kifer Rd, Sunnyvale, CA. 94086
tel: 408 523 8071; http://www.fast-chip.com
Opinions my own; statements of fact may be in error.