perldoc syn # 讀內建 perlsyn 文件 perldoc data # 讀內建 perldata 文件 perldoc WWW::Mechanize # 讀 WWW::Mechanize 模組內的文件 perldoc lib/Foo.pm # 讀 Foo.pm 檔案內容中所寫的文件
2013年2月25日 星期一
以 perldoc 程式讀文件
http://gugod.org/2009/07/-perldoc/
改變<br>的高度
http://stackoverflow.com/questions/1409649/how-to-change-height-of-a-br
chrome瀏覽器要加:
讓第四個以後的br高度消失
IE7, IE8要在jquery多加jquery-extra-selectors.js
br:nth-of-type(n+4) {
display: block;
margin-top: 0;
line-height: 0;
}
chrome瀏覽器要加:
content: " ";
讓第四個以後的br高度消失
IE7, IE8要在jquery多加jquery-extra-selectors.js
perl 匹配字串
http://www.cbi.pku.edu.cn/chinese/documents/perl/perl6.htm
http://blog.sina.com.cn/s/blog_50873f890100a13i.html
替換操作符
选项 描述
g 改变模式中的所有匹配
i 忽略模式中的大小写(case insensitive)
e 替换字符串作为表达式
m 将待匹配串视为多行
o 仅赋值一次
s 将待匹配串视为单行
x 忽略模式中的空白
二、匹配操作符 =~、!~
=~检验匹配是否成功:$result = $var =~ /abc/;若在该字符串中找到了该模式,则返回非零值,即true,不匹配则返回0,即false。!~则相反。
使用index去判斷匹配字串:
$filename = "bear_test-1234578";
print index($filename,"bear_test"); # 小於零時表示$filename與第二個參數("bear_test") 不匹配
搜尋中文: \p{Han}(未測試 ) 無法使用
http://www.regular-expressions.info/unicode.html#prop
其他特殊表示式:
http://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html
perl正規式的escape sequence
http://www.regular-expressions.info/characters.html
Escaping a single metacharacter with a backslash works in all regular expression flavors. Many flavors also support the \Q…\E escape sequence. All the characters between the \Q and the \E are interpreted as literal characters. E.g. \Q*\d+*\E matches the literal text *\d+*. The \E may be omitted at the end of the regex, so \Q*\d+* is the same as \Q*\d+*\E. This syntax is supported by the JGsoft engine, Perl, PCRE, PHP, Delphi, and Java, both inside and outside character classes. Java 4 and 5 have bugs that cause \Q…\E to misbehave, however, so you shouldn't use this syntax with Java.
=> 在perl正規式中\Q..\E中間的內容會被解釋為原文字符
http://blog.sina.com.cn/s/blog_50873f890100a13i.html
'' q// 字面字串 "" qq// 字面字串 `` qx// 命令執行 () qw// 單字串列 // m// 樣式比對 s/// s/// 樣式代換 y/// tr/// 字符轉譯 "" qr// 正規表示式 @test = qw/test perl is fun/; use Data::Dumper; print Dumper @test; #$VAR1 = 'test'; #$VAR2 = 'perl'; #$VAR3 = 'is'; #$VAR4 = 'fun'; $reg = "test"; $test = "atesta"; $test =~ s/$reg/bear/; print $test; #abeara `mkdir test2`; #建立test2資料夾 qx/mkdir test3/; #建立test2資料夾
替換操作符
选项 描述
g 改变模式中的所有匹配
i 忽略模式中的大小写(case insensitive)
e 替换字符串作为表达式
m 将待匹配串视为多行
o 仅赋值一次
s 将待匹配串视为单行
x 忽略模式中的空白
二、匹配操作符 =~、!~
=~检验匹配是否成功:$result = $var =~ /abc/;若在该字符串中找到了该模式,则返回非零值,即true,不匹配则返回0,即false。!~则相反。
使用index去判斷匹配字串:
$filename = "bear_test-1234578";
print index($filename,"bear_test"); # 小於零時表示$filename與第二個參數("bear_test") 不匹配
搜尋中文: \p{Han}
http://www.regular-expressions.info/unicode.html#prop
其他特殊表示式:
http://www.gnu.org/software/grep/manual/html_node/Character-Classes-and-Bracket-Expressions.html
perl正規式的escape sequence
http://www.regular-expressions.info/characters.html
Escaping a single metacharacter with a backslash works in all regular expression flavors. Many flavors also support the \Q…\E escape sequence. All the characters between the \Q and the \E are interpreted as literal characters. E.g. \Q*\d+*\E matches the literal text *\d+*. The \E may be omitted at the end of the regex, so \Q*\d+* is the same as \Q*\d+*\E. This syntax is supported by the JGsoft engine, Perl, PCRE, PHP, Delphi, and Java, both inside and outside character classes. Java 4 and 5 have bugs that cause \Q…\E to misbehave, however, so you shouldn't use this syntax with Java.
=> 在perl正規式中\Q..\E中間的內容會被解釋為原文字符
2013年2月18日 星期一
cakephp筆記
/tmp 要rewriteable
http://www.blogsdna.com/2159/how-to-take-ownership-grant-permissions-to-access-files-folder-in-windows-7.htm
cakephp 2.x (2.3.0)
php.ini要設定
extension=php_pdo_mysql.dll (Windows)
http://stackoverflow.com/questions/6212290/cake-is-not-able-to-connect-to-the-database
中文教程
http://www.ruiwant.com/cakephp2-blog-tutorials-part-1-installation-and-configuration.html
cakephp 下載(github)
http://www.ruiwant.com/cakephp2-blog-tutorials-part-1-installation-and-configuration.html
http://www.blogsdna.com/2159/how-to-take-ownership-grant-permissions-to-access-files-folder-in-windows-7.htm
cakephp 2.x (2.3.0)
php.ini要設定
extension=php_pdo_mysql.dll (Windows)
http://stackoverflow.com/questions/6212290/cake-is-not-able-to-connect-to-the-database
中文教程
http://www.ruiwant.com/cakephp2-blog-tutorials-part-1-installation-and-configuration.html
cakephp 下載(github)
http://www.ruiwant.com/cakephp2-blog-tutorials-part-1-installation-and-configuration.html
2013年2月8日 星期五
PERL 執行cron job (crontab)
http://jck11.pixnet.net/blog/post/4902321-利用lwp%3A%3Auseragent與網頁互動%5Bperl%5D
利用LWP::UserAgent與網頁互動[perl]
用perl去抓twitter的api把其中的資料存到主機上的檔案
http://stackoverflow.com/questions/8655487/how-to-convert-string-to-json-in-perl
How to convert string to json in perl
用UA抓回來的資料是字串
要把他轉為json
上文範例中的 use Try::Tiny; 是需要安裝的perl套件
安裝方法: $cpan Try::Tiny
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
15 Awesome Cron Job Examples
跑cron job
1. 查crontab有沒有在跑
$ service crond status
crond (pid 13616) is running...
$ crontab -e 進入編輯
寫入
00 * * * * /usr/bin/perl /home/xxx/cronjob/twitter_followers_count.pl
分 時 日 月 星期
(可先用 * * * * * 每分鐘跑 去看他有沒有跑 或者網路上有用到秒數的方法sleep)
ls -l 看那個檔案最後更新的時間
測試
$ ./your_cron_job.pl
對reference跑迴圈:
http://stackoverflow.com/questions/5249362/how-to-use-foreach-on-hash-a-reference
Crontab "*/1" 是什麼意思?
http://www.unix.com/linux/136805-crontab-1-a.html
*/1 * * * * /usr/local/bin/jdumpscan.sh
/1是多餘的,等同於每分鐘。等於
* * * * * /usr/local/bin/jdumpscan.sh
設定crontab -e 預設編輯器
http://superuser.com/questions/281617/change-default-text-editor-for-crontab-to-vim
如果預設編輯器不是vim,則使用下面指令設定
export VISUAL=vim
或
export EDITOR=vim
每30秒跑一次cronjob
http://stackoverflow.com/questions/9619362/running-a-cron-every-30-seconds
crontab -e:
* * * * * /usr/bin/bash /home/ds/test.sh
* * * * * ( sleep 30 ; /usr/bin/bash /home/ds/test.sh)
利用LWP::UserAgent與網頁互動[perl]
用perl去抓twitter的api把其中的資料存到主機上的檔案
#!/usr/bin/perl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use LWP::UserAgent; use HTTP::Headers; use JSON; our %SITE = ( 'aaa' => 'https://api.twitter.com/1/users/show.json?screen_name=aaa_account&include_entities=true', 'bbb' => 'https://api.twitter.com/1/users/show.json?screen_name=bbb_account&include_entities=true', ); &get_twitter_api(\%SITE); sub get_twitter_api { my $site = shift; my $url; my $class; my $agent_name='myagent'; my $ua=LWP::UserAgent->new($agent_name); foreach my $k (keys %$site) { $url = $site->{$k}; $class = $k; my $request=HTTP::Request->new(GET=>$url); $request->header(Accept=>'text/html'); my $response=$ua->request($request); my $decoded; my $content = $response->{_content}; $decoded = &JSON::decode_json($content); my $path = '>/XXX/files/'.$class.'/cron/twitter_followers_count.txt'; open (MYFILE, $path) || die "Can't open file $path : $!\n";; print MYFILE $decoded->{followers_count}; close (MYFILE); } }.
http://stackoverflow.com/questions/8655487/how-to-convert-string-to-json-in-perl
How to convert string to json in perl
用UA抓回來的資料是字串
要把他轉為json
上文範例中的 use Try::Tiny; 是需要安裝的perl套件
安裝方法: $cpan Try::Tiny
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
15 Awesome Cron Job Examples
跑cron job
1. 查crontab有沒有在跑
$ service crond status
crond (pid 13616) is running...
$ crontab -e 進入編輯
寫入
00 * * * * /usr/bin/perl /home/xxx/cronjob/twitter_followers_count.pl
分 時 日 月 星期
(可先用 * * * * * 每分鐘跑 去看他有沒有跑 或者網路上有用到秒數的方法sleep)
ls -l 看那個檔案最後更新的時間
測試
$ ./your_cron_job.pl
對reference跑迴圈:
http://stackoverflow.com/questions/5249362/how-to-use-foreach-on-hash-a-reference
foreach my $key (keys %{ $ad_grp_ref }) { ... }
Crontab "*/1" 是什麼意思?
http://www.unix.com/linux/136805-crontab-1-a.html
*/1 * * * * /usr/local/bin/jdumpscan.sh
/1是多餘的,等同於每分鐘。等於
* * * * * /usr/local/bin/jdumpscan.sh
設定crontab -e 預設編輯器
http://superuser.com/questions/281617/change-default-text-editor-for-crontab-to-vim
如果預設編輯器不是vim,則使用下面指令設定
export VISUAL=vim
或
export EDITOR=vim
每30秒跑一次cronjob
http://stackoverflow.com/questions/9619362/running-a-cron-every-30-seconds
crontab -e:
* * * * * /usr/bin/bash /home/ds/test.sh
* * * * * ( sleep 30 ; /usr/bin/bash /home/ds/test.sh)
訂閱:
文章 (Atom)