Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: URL resolve (operations on path etc.)

by haukex (Archbishop)
on Jul 31, 2022 at 07:52 UTC ( #11145864=note: print w/replies, xml ) Need Help??


in reply to URL resolve (operations on path etc.)

use warnings; use strict; use URI; my $x = 'http://a.com/a/b/c/d/e.json?x=1&y=2'; my $y = '../../../'; my $u = URI->new($y); print $u->abs($x), "\n"; __END__ http://a.com/a/

Replies are listed 'Best First'.
Re^2: URL resolve (operations on path etc.)
by bliako (Monsignor) on Jul 31, 2022 at 08:03 UTC

    Thanks haukex++ (I swear last night abs was not working!!!!!!)

    EDIT!: ouchhhh I was doing the reverse!!!!!:

    # this is wrong, note new($x)!! abs($y) it should be the reverse my $u = URI->new($x); # this is wrong print $u->abs($y), "\n"; # this is wrong

    Edit2: that's definetely an X-Y problem hehe

Re^2: URL resolve (operations on path etc.)
by ikegami (Patriarch) on Aug 01, 2022 at 22:50 UTC
Re^2: URL resolve (operations on path etc.)
by harangzsolt33 (Friar) on Jul 31, 2022 at 11:31 UTC
    Could this be resolved with a regex maybe? Like for example:

    #!/usr/bin/perl use strict; use warnings; my $PATH = 'http://a.com/a/b/c/d/e.json?something' . '/' . '/../../../ +'; $PATH =~ tr|/||s; my $PREV = 0; my $LEN; for (;;) { $PATH =~ s/\/[^\/]+\/\.\.//; $LEN = length($PATH); last if ($PREV == $LEN); $PREV = $LEN; } print $PATH;

    I put the regex in a for(;;) loop, because adding global flag didn't do what I want:

    $PATH =~ s/\/[^\/]+\/\.\.//g;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145864]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-09-25 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?