On Fri, Oct 22, 2021 at 8:45 AM ToddAndMargo via perl6-users
<perl6-us...@perl.org> wrote:
>
> >> On 10/21/21 22:03, Kevin Pye wrote:
> >>>
> >>> Why not just use the Perl Net::FTP?
> >>
> >> I use that in Perl 5.
> >> I am trying to divorce myself of Perl 5.

Please consider not divorcing yourself from Perl
stuff you know works until you have hit problems
in Perl code that you absolutely know you cannot
fix OR you KNOW it works in Raku.

Taking the "use Perl" approach will in general be
very helpful to Raku, AND to Rakoons, AND to Perl,
AND for solving problems, AND for your clients,
AND for yourself, even if it feels otherwise at first.

Here's how I suggest you get going. Post back
here if you get stuck.

1. Install Perl's Net::FTP.

2. Write `use Net::FTP:from<Perl5>;` in your
Raku program. In other words, just like you
would in Perl, but appending `:from<Perl5>`
to the package name.

3. Write ordinary Raku code as if Net::FTP
was written in Raku.

For example, here's the start of the synopsis from
https://metacpan.org/pod/Net::FTP#SYNOPSIS

use Net::FTP;

$ftp = Net::FTP->new("some.host.name", Debug => 0)
  or die "Cannot connect to some.host.name: $@";

So, to do the same thing, but using Raku instead of Perl,
you'd install the module as usual, and then you'd write
the following in a Raku program:

use Net::FTP:from<Perl5>;

my $ftp = Net::FTP.new("some.host.name", Debug => 0)
  or die "Cannot connect to some.host.name: $!";

Note how you have to write Raku code, not Perl code,
even though you're using a Perl module. So I've used:

* `my`. Unlike in Perl, you can't omit that.

* `.` instead of `->`. Raku uses `.` for method calls.

* `$!` instead of `$@`. Raku uses `$!` for exceptions, unlike Perl's `$@`.

I'm not sure if the `debug => 0` is going to work. But
try it and see what happens.

So that's the approach.

You use a Perl module that used to work for you, or that
you think should work for you. You tack a `:from<Perl5>`
onto the end of the `use` statement. Then you write Raku
code, making sure to translate any Perl syntax, special
variables, and so on, to their Raku equivalent.

For your first couple goes at this you might trip up over
simple things, and we might also struggle to help you
even though they're simple things.

But after you/we get two or so simpler uses of existing
Perl modules in Raku under our collective belts, we'll
have a hugely important new thing happening, and the
World will become a much better place because of it. :)

--
love, raiph

Reply via email to