In a message dated Mon, 11 Sep 2006, Richard Hainsworth writes:
I am trying to find out how to use (in perl6) perl5 modules that contain
subroutines.
Imports from Perl 5 modules don't currently work.
You can workaround this using .can, see below.
use perl5:Time::gmtime;
my $gm = gmtime();
printf "The day in Greenwich is %s\n",
(qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ $gm.wday() ];
# note the change from -> to .
use v6-alpha;
use perl5:Time::gmtime;
our &gmtime := Time::gmtime.can('gmtime');
my $gm = gmtime();
say "The day in Greenwich is {(<Sun Mon Tue
Wed Thu Fri Sat Sun>)[ $gm.wday ] }";
There is no printf. You can use a string closure as above, or
say/print with sprintf.
The same goes for your other example:
use perl5:Text::Balanced qw(extract_tagged);
my $txt = '<atag>now and then</atag>some text';
my @ret_pars = extract_tagged($txt); # this is line 8
print join("\n",@ret_pars),"\n";
#print "[EMAIL PROTECTED]" if $@;
# commented this out as caused a compile error, probably another
# variable should be used for errors.
use perl5:Text::Balanced;
our &extract_tagged := Text::Balanced.can('extract_tagged');
my $txt = '<atag>now and then</atag>some text';
my @ret_pars = extract_tagged($txt); # this is line 8
.say for @ret_pars;
say $! if $!;
$@ is no more, it's $! for all errors whatever their provender. In this
case there's no need for a join, but you could have written it:
say @ret_pars.join("\n");
if you liked.
All that said, there's a problem with Text::Balanced running under pugs;
@ret_pars is reversed from what it should be. I'm not sure what's going
on.
Trey