Re: hellp improve efficiency
Hi, You can use the following it will reduce the amount of : ... while () { $uri = (split)[0]; $uri =~ s#www\.example\.com/(v\d?|so)#$1.example.com# or $uri =~ s#www\.example\.com/admin/\?.*#www.example.com/admin/# or $uri =~ s#www\.example\.com/([wulp])(\d+)/#$2.$1.example.com# or $uri =~ s#www\.example\.com/([wulp])/#$1.example.com/#; print $uri; } Best regards Yaron Kahanovitch - Original Message - From: Jen mlists [EMAIL PROTECTED] To: beginners perl beginners@perl.org Sent: Saturday, April 28, 2007 10:57:07 AM (GMT+0200) Auto-Detected Subject: 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. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: hellp improve efficiency
On 4/28/07, Jen mlists [EMAIL PROTECTED] wrote: }elsif ($uri =~ m|www\.example\.com/v2/|o) { $uri =~ s|www\.example\.com/v2/|v2.example.com/|; The /o modifier isn't desirable there. Also, because a s/// will only replace if the match part succeeds, you can skip the test: $uri =~ s#www\.example\.com/v2/#v2.example.com/#; If it matters to you whether the pattern matched or not, you may test the result in a scalar context: } elsif ($uri =~ s#www\.example\.com/v2/#v2.example.com/#) { # substitution succeeded, do nothing further } elsif (...) { Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: hellp improve efficiency
Perhaps I'm misunderstanding what you're ultimately trying to accomplish. However, if you're doing what I think you're doing and you're using Apache, look into mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html - sf Jen mlists wrote: 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. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: hellp improve efficiency
2007/4/29, Steve Finkelstein [EMAIL PROTECTED]: Perhaps I'm misunderstanding what you're ultimately trying to accomplish. However, if you're doing what I think you're doing and you're using Apache, look into mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html From my knowledge,he/she was doing nothing about Apache,but wrote a redirector for Squid cache. Also Tom,maybe using or instead of elsif is more clear,:) $uri =~ s#www\.example\.com/v2/#v2.example.com/# or $uri =~ s#www\.example\.com/v3/#v3.example.com/# or -- Chinese Practical Mod_perl book online http://home.arcor.de/jeffpang/mod_perl/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/