Created
September 19, 2015 17:03
-
-
Save Marthym/546a2efa7d38c9da5dcc to your computer and use it in GitHub Desktop.
This file contains 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 | |
use strict; | |
use warnings; | |
$|=1; | |
my %url; | |
# read config file | |
open CONF, $ARGV[0] or die "Error opening $ARGV[0]: $!"; | |
while (<CONF>) { | |
chomp; | |
next if /^\s*#?$/; | |
my @l = split("\t"); | |
$url{qr/$l[0]/} = $l[$#l]; | |
} | |
close CONF; | |
# read urls from squid and do the replacement | |
URL: while (<STDIN>) { | |
chomp; | |
last if /^(exit|quit|x|q)$/; | |
foreach my $re (keys %url) { | |
if (my @match = /$re/) { | |
$_ = $url{$re}; | |
for (my $i=1; $i<=scalar(@match); $i++) { | |
s/\$$i/$match[$i-1]/g; | |
} | |
print "OK store-id=$_\n"; | |
next URL; | |
} | |
} | |
print "ERR\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment