
Perl
EricYeung
这个作者很懒,什么都没留下…
展开
-
Perl Regex: Extract Key Value Pair
#! perl -w$/ = "/n";$str = "Color=red";($k, $v) = ($str =~ m/(/w+)=(/w*)/);$ret = ($str =~ m/(/w+)=(/w*)/);print "Key = $k, Value = $v";print $ret;# one liner version$ret = (($k,原创 2005-12-23 11:12:00 · 1297 阅读 · 0 评论 -
A Cgi Set Cookies
#! c:/perl/bin/perl.exeuse CGI qw/:standard/;$cookie = cookie(-name=>menus, -value=>on, -expires=>+30d, -path=>/);print header(-cookie=>$cookie);print start_html(-原创 2006-02-22 22:05:00 · 1029 阅读 · 0 评论 -
Upload File Cgi Sample
#! c:/perl/bin/perluse CGI;$q = new CGI;$upload_dir = "portraits";if ($q->param(portrait)) { &print_page_start; &write_file; &print_page_end;}else { &print_page原创 2006-02-22 22:11:00 · 1608 阅读 · 0 评论 -
A Cgi print Environment Variables
#!c:/Perl/bin/Perl.exeuse CGI;$q = new CGI;print $q->header;foreach $var (sort(keys(%ENV))) { $val = $ENV{$var}; $val =~ s|/n|//n|g; $val =~ s|"|//"|g; print "${var}=原创 2006-02-22 22:04:00 · 892 阅读 · 0 评论 -
Guest Book Cgi
#!c:/Perl/bin/Perl.exeuse strict; # enforce declarations and quotinguse CGI qw(:standard); # import shortcutssub bail { # function to handle errors gracefully my $error = "@_"; pri原创 2006-02-22 22:14:00 · 4661 阅读 · 0 评论 -
A Cgi Get Cookies
#! c:/perl/bin/perl.exeuse CGI qw/:standard *table/;use strict;print header;print start_html(cookies);print h3(Cookies);print start_table(-border=>"1");print Tr([ th([name, va原创 2006-02-22 22:16:00 · 1101 阅读 · 0 评论 -
First Perl CGI Example
#!c:/Perl/bin/Perl.exeuse strict;use CGI qw(:standard);print header, start_html(a simple cgi), h1(a simple example), start_form, "whats you name?", textfield(name)原创 2006-02-22 22:00:00 · 1296 阅读 · 0 评论 -
Perl Mgmt Tips: rename file
我在网上下载一些书籍是用rar切割成的一些rar文件,例如下载的文件是20060601=FILEpart01.rar20067802=FILEpart02.rar20062303=FILEpart03.rar而要快速解压,要把这些文件名改成FILEpart01.rarFILEpart02.rarFILEpart03.rar然后解压part01就可以,他会自动找同名的原创 2006-05-05 12:03:00 · 1049 阅读 · 0 评论 -
Web Mail Cgi
#! c:/perl/bin/perl.exeuse strict;use CGI;use Net::SMTP;my $q = new CGI;my $smtp = Net::SMTP->new(localhost);my $address = "webmaster/@rc3.org";my $err = "";my ($from, $subject原创 2006-02-22 22:18:00 · 1529 阅读 · 0 评论 -
Perl: map print
#! perl -w$/ = "/n";my @array = qw/a b c d e f/;map {print} @array; #eqivalent to "print foreach @array" "print @array"foreach (@array) { print;}print foreach @array;print @array;原创 2005-12-23 11:15:00 · 1048 阅读 · 0 评论 -
Perl Regex: execute perl code in RegEx
#execute perl code in RegEx___FCKpd___0 = "abcdef";if ( /abc(?{print "Hi Mom!/n";})def/ ) { print "crazy perl code in RegEx/n";}原创 2005-12-23 11:13:00 · 973 阅读 · 0 评论 -
Perl Regex: lookahead & lookforeword matching
#lookahead & lookforeword matching___FCKpd___0 = "tom cat";if ( /tom(?=cat)/ ) { print "find tom, follow by cat/n";}if ( /(?!tom)cat/ ) { print "find cat, and tom is in front o原创 2005-12-23 11:14:00 · 1119 阅读 · 0 评论 -
Perl Regex: multi-line match
#! perl -w$/ = "/n";$_ = "line_a/nline_b";if ( /a(.*)b/s ) { print $1}原创 2005-12-23 11:17:00 · 1163 阅读 · 0 评论 -
Perl Regex: non-captured parentheses
___FCKpd___0 = " abc def";if ( //s+(?:/w+)/s+(/w+)/) { if (defined($1)){ print "capture /$1 = $1";} print "/t"; if (defined($2)){ print "capture /$2 = $2";}}原创 2005-12-23 11:18:00 · 1058 阅读 · 0 评论 -
Perl Regex: usage of non capturing, (more powerful split)
#! perl -w$/ = "/n";use Data::Dumper;#usage of non capturing, (more powerful split)___FCKpd___0 = 12a34b5;print "string = ".___FCKpd___0."/n";@num = split /(a|b)/;print "captur原创 2005-12-23 11:19:00 · 1005 阅读 · 0 评论 -
Perl Regex: extract words
#! perl -w$/ = "/n";#print ($0 =~ /([^////]*?)$/ ); this is a comment$foo = "word1 is2 the remain ...";($f1, $f2, $etc) = split( , $foo, 3);print $f1;print $f2;print $etc;#do t原创 2005-12-23 11:21:00 · 1070 阅读 · 0 评论 -
Perl Regex: swap words
#!perl -w$/ = "/n";$_ = "one two remainder ... ";s/([^ ]*) *([^ ]*)/$2 $1/;print;原创 2005-12-23 11:21:00 · 969 阅读 · 0 评论 -
在Windows上用Perl模拟Unix的Which命令
// 找岀notepad.exe在环境变量path中的哪些目录里C:/>perl -e "foreach(split(;, $ENV{path})) { print $_. if -e $_./"//notepad.exe/"; }output:C:/WINDOWS/system32 C:/WINDOWS原创 2005-12-25 11:46:00 · 1427 阅读 · 0 评论 -
Perl common usage
Perl common usage原创 2011-01-20 18:51:00 · 910 阅读 · 0 评论