http://qs321.pair.com?node_id=11145864


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 (Chaplain) 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;