hellp improve efficiency
- From: practicalperl@xxxxxxxxx (Jen mlists)
- Date: Sat, 28 Apr 2007 15:57:07 +0800
Hello members,
I wrote a perl script for url redirect,shown as below,
$|=1;
my $uri = '';
while (<>) {
$uri = (split)[0];
if ($uri =~ /\.html?\?/ or $uri =~ /\.js\?/ or $uri =~ /\.css\?/ or
$uri =~ /\.jpg\?/ or $uri =~ /\.gif\?/ or $uri =~ /\.swf\?/) {
$uri =~ s/\?.*$//;
}
if ($uri =~ m|www\.example\.com/v/|o) {
$uri =~ s|www\.example\.com/v/|v.example.com/|;
}elsif ($uri =~ m|www\.example\.com/v2/|o) {
$uri =~ s|www\.example\.com/v2/|v2.example.com/|;
}elsif ($uri =~ m|www\.example\.com/v3/|o) {
$uri =~ s|www\.example\.com/v3/|v3.example.com/|;
}elsif ($uri =~ m|www\.example\.com/so/|o) {
$uri =~ s|www\.example\.com/so/|so.example.com/|;
}elsif ($uri =~ m|www\.example\.com/admin/\?.*|o) {
$uri =~ s|www\.example\.com/admin/\?.*|www.example.com/admin/|;
}elsif ($uri =~ m|www\.example\.com/w\?v=|o) {
$uri =~ s|www\.example\.com/w\?v=|v2.example.com/v_|;
}elsif ($uri =~ m|www\.example\.com/([wulp])(\d+)/|o) {
$uri =~ s|www\.example\.com/([wulp])(\d+)/|$2.$1.example.com/|;
}elsif ($uri =~ m|www\.example\.com/([wulp])/|o) {
$uri =~ s|www\.example\.com/([wulp])/|$1.example.com/|;
}
} continue {
print "$uri\n";
}
__END__
As you see,for each regex match,I've tested it twice.
Maybe it's going with low-efficiency.How can improve it?Thanks.
.
- Follow-Ups:
- Re: hellp improve efficiency
- From: yaron
- Re: hellp improve efficiency
- From: Steve Finkelstein
- Re: hellp improve efficiency
- From: Tom Phoenix
- Re: hellp improve efficiency
- Prev by Date: Re: How to enable/disable the "use strict" at run-time?
- Next by Date: MP3::Tag and UTF8 output
- Previous by thread: Wild card link matching
- Next by thread: Re: hellp improve efficiency
- Index(es):
Relevant Pages
|