How do I download a file using Perl?

后端 未结 4 633
天涯浪人
天涯浪人 2020-12-23 10:14

I\'m running Perl on Windows XP, and I need to download a file from the URL http://marinetraffic2.aegean.gr/ais/getkml.aspx.

How should I do this? I have attempted u

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 10:44

    I used File::Fetch as this is a core Perl module (I didn't need to install any additional packages) and will try a number of different ways to download a file depending on what's installed on the system.

    use File::Fetch;
    my $url = 'http://www.example.com/file.txt';
    my $ff = File::Fetch->new(uri => $url);
    my $file = $ff->fetch() or die $ff->error;
    

    Note that this module will in fact try to use LWP first if it is installed...

提交回复
热议问题