Pathname from URL

A

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 !
 
P

Peter Makholm

Andre Majorel said:
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
 
G

George Mpouras

Στις 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/~a/b/c?d=e/f#g');
my $scheme = $url->scheme;

(my $what_you_want = $url->canonical)=~s/^$scheme:\/\///;
say $what_you_want;
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top