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 !

    --
    André Majorel http://www.teaser.fr/~amajorel/
    Endless variations make it all seem new
    Can you recognise the patterns that you find ?
    Andre Majorel, Apr 16, 2014
    #1
    1. Advertising

  2. Andre Majorel <> writes:

    > 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 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. Advertising

  3. Στις 16/4/2014 12:28, ο/η Andre Majorel έγÏαψε:
    > 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 !
    >





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

    my $url = URI->new('http://foobar.org/%7Ea/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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Vercuski

    Access to the path <pathname> is denied.

    Scott Vercuski, Feb 25, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    515
    Arvind P Rangan
    Feb 25, 2004
  2. Ike

    Windows pathname hell

    Ike, Feb 19, 2004, in forum: Java
    Replies:
    11
    Views:
    4,464
    Pete Gieser
    Feb 21, 2004
  3. Rakesh Pandit
    Replies:
    0
    Views:
    494
    Rakesh Pandit
    Jul 12, 2005
  4. Black Baptist
    Replies:
    5
    Views:
    2,303
    Black Baptist
    Jan 14, 2005
  5. Black Baptist
    Replies:
    1
    Views:
    861
    Black Baptist
    Jan 28, 2005
Loading...

Share This Page