Pathname from URL

Discussion in 'Perl Misc' started by Andre Majorel, Apr 16, 2014.

  1. Looking for Perl code to convert a URL like

    http://foobar.org/~a/b/c?d=e/f#g

    to a Unix pathname like

    foobar.org/~a/b/c?d=e%2Ff

    The same sort of thing that wget -x does.

    Even better if it offers the option of honouring the
    Content-disposition HTTP header.

    Thanks in advance !
     
    Andre Majorel, Apr 16, 2014
    #1
    1. Advertisements

  2. The generalt module for parsing URL's would be URI.pm. This will help
    you with parsing the url into the individual parts. Putting this
    together into the actual filename is probably something you'll need to
    do yourself.

    //Makholm
     
    Peter Makholm, Apr 16, 2014
    #2
    1. Advertisements

  3. Στις 16/4/2014 12:28, ο/η Andre Majorel έγÏαψε:



    #!/usr/bin/perl
    use strict;
    use warnings;
    use feature qw/say/;
    use URI;

    my $url = URI->new('http://foobar.org/~a/b/c?d=e/f#g');
    my $scheme = $url->scheme;

    (my $what_you_want = $url->canonical)=~s/^$scheme:\/\///;
    say $what_you_want;
     
    George Mpouras, Apr 18, 2014
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.