hellp improve efficiency



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.
.



Relevant Pages

  • What could potentially be wrong in this script?
    ... I am writing a Perl script to check that dependency files exist that ... opening it, and then based on the type of file, saving a regex to ... foreach my $files ... The index call isn't working on this bizarre string. ...
    (comp.lang.perl.misc)
  • Re: space deliminated to comma delinated with varried and need spaces between some columns
    ... > Notice the white spaces at beginning of the line, I DONT WANT THEM THERE ... > I need to created a perl script that takes this file and makes it look like ... I get the idea I may be oversimplifying or misunderstanding some part ... If there's a need to write it to a file of another name the same regex ...
    (comp.lang.perl.misc)
  • Re: Fast Substring to get URL?
    ... Use System.Uri class, which provides complete facilities for URI ... Don't use Regex. ... using either Regex or a custom function based on Uri ...
    (microsoft.public.dotnet.framework)
  • Re: appending to file appends twice!?
    ... > I wrote a Perl script to append Questions and Answers to a text data file. ... > increment as if my routine is called twice. ... so chances are it is being called twice somehow. ...
    (comp.lang.perl.misc)
  • Re: Help With Pattern Matching
    ... > I'm trying to write a Perl script that processes each word in a file and ... some with a "p" in them, but none in upper case. ... Change your regex to ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)