Created
June 17, 2019 23:28
-
-
Save alogic0/89c10a66e994a204f9b91c6fedfee7ec to your computer and use it in GitHub Desktop.
Exchange "to" and "from" parameters in a URL to booking.uz.gov.ua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
## Usage: $0 'https://booking.uz.gov.ua/ru/?time=00%3A00&url=train-wagons&date=2019-08-01&from=2218020&wagon_type_id=%D0%9F&train=058%D0%9B&to=2208001' | |
use v5.14; | |
use strict; | |
use warnings; | |
say $ARGV[0]; | |
$_=$ARGV[0]; | |
chomp; | |
m@^(.*/\?)@; | |
my $prefix=$1; | |
s@^.*/\?@@; | |
s/[&=]/ /g; | |
my %params=split; | |
my @all_params=split; | |
my @keys; | |
foreach my $n (0..($#all_params + 1)/2 - 1) { | |
$keys[$n] = $all_params[$n*2] | |
} | |
($params{to}, $params{from})=($params{from}, $params{to}); | |
foreach my $k (@keys) { | |
print "$k $params{$k}\n"; #DEBUG | |
$prefix.=$k."=".$params{$k}."\&" | |
} | |
$_=$prefix; | |
s/&$//g; | |
say; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment