自己写的browse.bat与perl写的url_handler.pl的比较
以前自己也写过Windows下自动打开多个浏览器测试某个URI,提高浏览器兼容性测试效率。
但是写的browse.bat文件还是最基础简陋的
@echo off
if '%1'=='-c' (
start /d "C:\Program Files\Google\Chrome\Application\" chrome.exe -new-tab %2
exit
)
if '%1'=='-f' (
start /d "C:\Program Files\Mozilla Firefox" firefox.exe -new-tab %2
exit
)
if '%1'=='-i' (
start /d "C:\Program Files\Internet Explorer" iexplore.exe %2
exit
)
if '%1'=='-d' (
rundll32 url.dll,FileProtocolHandler %2
exit
) if '%1'=='-a' (
call browse -c %2
call browse -f %2
call browse -i %2
) else (
explorer %1
今天恰巧看到cygwin安装目录下用perl写的url_handler.pl,感觉作者的思路挺有趣。
代码共赏析:C:\cygwin\bin\url_handler.pl
if ($ENV{BROWSER}) {
push(@try, split(/:/, $ENV{BROWSER}));
} else { # set some defaults
push(@try, 'firefox -a firefox -remote openURL\(%s\)');
push(@try, 'mozilla -remote openURL\(%s\)');
push(@try, 'opera -remote openURL\(%s\)');
push(@try, 'galeon -n');
push(@try, 'lynx'); # prefer lynx over links as it can handle news:-urls
push(@try, qw('links2 -g' links w3m));
push(@try, 'kfmclient newTab'); # has no useful return-value on error
}
上面的亮点:
1.使用了@try这样一个思路,尝试打开.(没有理解perl的@try的含义?)
2.没有用很多的if-else而是用push放入一个数组(没有查阅过perl的push含义?)
#! /usr/bin/perl -w
# example of how to call an appropriate viewer
#
# URLs must start with a scheme and shell metas should be already quoted
# (tin doesn't recognize URLs without a scheme and it quotes the metas) use strict;
use warnings; (my $pname = $) =~ s#^.*/##;
die "Usage: $pname URL" if $#ARGV != 0; # version Number
my $version = "0.1.1"; my ($method, $url, $match, @try);
$method = $url = $ARGV[];
$method =~ s#^([^:]+):.*#$1#io; # shell escape
$url =~ s#([\&\;\`\'\\\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\010\013\020\011])#\\$1#g; if ($ENV{"BROWSER_".uc($method)}) {
push(@try, split(/:/, $ENV{"BROWSER_".uc($method)}));
} else {
if ($ENV{BROWSER}) {
push(@try, split(/:/, $ENV{BROWSER}));
} else { # set some defaults
push(@try, 'firefox -a firefox -remote openURL\(%s\)');
push(@try, 'mozilla -remote openURL\(%s\)');
push(@try, 'opera -remote openURL\(%s\)');
push(@try, 'galeon -n');
push(@try, 'lynx'); # prefer lynx over links as it can handle news:-urls
push(@try, qw('links2 -g' links w3m));
push(@try, 'kfmclient newTab'); # has no useful return-value on error
}
} for my $browser (@try) {
# ignore empty parts
next if ($browser =~ m/^$/o);
# expand %s if not preceded by odd number of %
$match = $browser =~ s/(?<!%)((?:%%)*)%s/$$url/og;
# expand %c if not preceded by odd number of %
$browser =~ s/(?<!%)((?:%%)*)%c/$:/og;
# reduce dubble %
$browser =~ s/%%/%/og;
# append URL if no %s expansion took place
$browser .= " ".$url if (!$match);
# leave loop if $browser was started successful
last if (system("$browser 2>/dev/null") == );
}
exit ; __END__ =head1 NAME url_handler.pl - Spawn appropriate viewer for a given URL =head1 SYNOPSIS B<url_handler.pl> I<URL> =head1 DESCRIPTION B<url_handler.pl> takes an URL as argument and spawns the first executable
viewer found in either B<$BROWSER_I<SCHEME>> or B<$BROWSER>. =head1 ENVIRONMENT =over =item B<$BROWSER_I<SCHEME>> The user's preferred utility to browse URLs of tye I<SCHEME>. May actually
consist of a sequence of colon-separated browser commands to be tried in
order until one succeeds. If a command part contains %s, the URL is
substituted there, otherwise the browser command is simply called with the
URL as its last argument. %% is replaced by a single percent sign (%), and
%c is replaced by a colon (:).
Examples: =over 4 =item $BROWSER_FTP="wget:ncftp" =item $BROWSER_GOPHER="lynx:links" =item $BROWSER_MAILTO="mutt:pine -url" =item $BROWSER_NEWS="lynx" =item $BROWSER_NNTP="lynx" =back Z<> =item B<$BROWSER> The user's preferred utility to browse URLs for which there is no special
viewer defined via B<$BROWSER_I<SCHEME>>. Again it may actually consist of a
sequence of colon-separated browser commands to be tried in order until one
succeeds. If a command part contains %s, the URL is substituted there,
otherwise the browser command is simply called with the URL as its last
argument. %% is replaced by a single percent sign (%), and %c is replaced
by a colon (:).
Examples: =over =item $BROWSER="firefox -a firefox -remote openURL\(%s\):opera:konqueror:links2 -g:lynx:w3m" =back =head1 SECURITY B<url_handler.pl> was designed to work together with B<tin>() which only
issues shell escaped absolute URLs thus B<url_handler.pl> does not try hard
to shell escape its input nor does it convert relative URLs into absolute
ones! If you use B<url_handler.pl> from other applications be sure to at
least shell escaped its input! =head1 AUTHOR Urs Janssen E<lt>urs@tin.orgE<gt> =head1 SEE ALSO http://www.catb.org/~esr/BROWSER/
http://www.dwheeler.com/browse/secure_browser.html =cut
自己写的browse.bat与perl写的url_handler.pl的比较的更多相关文章
- 横竖两个数字塔的效果BAT批处理怎么写?
横竖两个数字塔的效果BAT批处理怎么写?@echo offfor /l %%a in (0,1,1) do ( for /l %%i in (0,1,9) do ( for ...
- 再议perl写多线程端口扫描器
再议perl写多线程端口扫描器 http://blog.csdn.net/sx1989827/article/details/4642179 perl写端口多线程扫描器 http://blog.csd ...
- 瞧一瞧,看一看呐,用MVC+EF快速弄出一个CRUD,一行代码都不用写,真的一行代码都不用写!!!!
瞧一瞧,看一看呐用MVC+EF快速弄出一个CRUD,一行代码都不用写,真的一行代码都不用写!!!! 现在要写的呢就是,用MVC和EF弄出一个CRUD四个页面和一个列表页面的一个快速DEMO,当然是在不 ...
- 刺猬大作战(游戏引擎用Free Pascal写成,GUI用C++写成,使用SDL和Qt4)
游戏特性[编辑] 游戏引擎用Free Pascal写成,GUI用C++写成,使用SDL和Qt4[2]. 0.9.12开始支持实时动态缩放游戏画面. 个性化[编辑] 刺猬大作战有着高度定制性 游戏模式: ...
- php 写内容到文件,把日志写到log文件
php 写内容到文件,把日志写到log文件 <?php header("Content-type: text/html; charset=utf-8"); /******** ...
- 以前写SpringMVC的时候,如果需要访问一个页面,必须要写Controller类,然后再写一个方法跳转到页面,感觉好麻烦,其实重写WebMvcConfigurerAdapter中的addViewControllers方法即可达到效果了
以前写SpringMVC的时候,如果需要访问一个页面,必须要写Controller类,然后再写一个方法跳转到页面,感觉好麻烦,其实重写WebMvcConfigurerAdapter中的addViewC ...
- 出错的方法有可能是JDK,也可能是程序员写的程序,无论谁写的,抛出一定用throw
应对未检查异常就是养成良好的检查习惯. 已检查异常是不可避免的,对于已检查异常必须实现定义好应对的方法. 已检查异常肯定跨越出了虚拟机的范围.(比如“未找到文件”) 如何处理已检查异常(对于所有的已检 ...
- C++代写,代写C++,C++程序代写,C++ assignment代写
C++代写,代写C++,C++程序代写 关于C++代写,我们的涉猎范围: C++数据结构.算法题目 C++操作系统os题目 C++网络编程networking题目 C++ Linux题目 C++ Wi ...
- 剖析手写Vue,你也可以手写一个MVVM框架
剖析手写Vue,你也可以手写一个MVVM框架# 邮箱:563995050@qq.com github: https://github.com/xiaoqiuxiong 作者:肖秋雄(eddy) 温馨提 ...
随机推荐
- UVA548-Tree(二叉树数组表示)
Problem UVA548-Tree Accept: 2287 Submit: 13947 Time Limit: 3000 mSec Problem Description You are to ...
- BZOJ1935:[SHOI2007]Tree 园丁的烦恼(CDQ分治)
Description 很久很久以前,在遥远的大陆上有一个美丽的国家.统治着这个美丽国家的国王是一个园艺爱好者,在他的皇家花园里种植着各种奇花异草.有一天国王漫步在花园里,若有所思,他问一个园丁道: ...
- P2626 斐波那契数列(升级版)(合数的质数分解, 大数为素数的概率十分小的利用)
题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: f(1)=1f(1) = 1 f(1)=1 f(2)=1f(2) = 1f(2)=1 f(n)=f(n−1)+f(n−2)f(n) = f ...
- go-simplejson文档学习
https://godoc.org/github.com/bitly/go-simplejson 导入方式: import "github.com/bitly/go-simplejson&q ...
- 解决VC++6.0打开文件或添加文件到工程出错的问题
相信很多朋友在安装VC++6.0之后,发现无法使用打开文件命令.同时,打开了工程,却无法实现文件添加到工程的问题.一旦进行如此操作,便会出现应用程序错误,需要关闭应用程序.为此,不胜其烦.更有甚者,以 ...
- heap堆算法的使用分析
新生代 --复制算法 老年代 --标记压缩清除算法 分代 分区思想 垃圾回收的任务是识别和回收垃圾对象进行内存清理,为了让垃圾回收器可以高效的执行,大部分情况下,会要求系统进入一个停顿的状态. 停顿 ...
- jmeter(十二)关联之正则表达式提取器
如果有这样的情况:一个完整的操作流程,需要先完成某个操作,获得某个值或数据信息,然后才能进行下一步的操作(也就是常说的关联/将上一个请求的响应结果作为下一个请求的参数): 在jmeter中,可以利用正 ...
- SkylineGlobe 支持火狐和谷歌浏览器的可运行示例代码
示例代码: <html> <head> <title>3dml的Feature对象选中和隐藏</title> <script type=" ...
- Literal 字面值 字面量 的理解
Literal 字面值 字面量 Literal, 在程序语言中,指表示某种数据值的符码.如,123 是整数值符码, 3.14 是浮点值符码,abcd 是字串值符码,True, False, 是逻辑值符 ...
- UOJ219 NOI2016 优秀的拆分 二分、字符串哈希
传送门 题目可以转化为求\(AA\)的数量,设\(cnt1_x\)表示左端点为\(x\)的\(AA\)的数量,\(cnt2_x\)表示右端点为\(x\)的\(AA\)的数量,那么答案就是\(\sum ...