Perl单行脚本显示历史命令使用频率


在网上看到这个脚本感觉很不错,记录一下:

history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr
 7 sort
 6 ls
 5 history
 5 clear
 4 uniq
 4 perl
 3 telnet
 3 head
 3 cd
 3 alne
 2 pwd
 1 cat



Perl用Web::Scraper的Xpath方法采集数据放入MySQL


采集新浪一小块新闻的标题.url.内容,并存入MySQL数据库,多谢一位兄弟的帮忙才得以完成.速度还不是很理想,下一步看看能不能用上多线程.一步步提高自己的Perl水平.

#!/usr/bin/perl
use warnings;
use URI;
use Web::Scraper;
use utf8;
binmode(STDIN, ‘:encoding(utf8)’);
binmode(STDOUT, ‘:encoding(utf8)’);
binmode(STDERR, ‘:encoding(utf8)’);
use DBI;
use strict;
my $user = "root";
my $passwd = "123456";
my $data_source = "dbi:mysql:tes20";
my $dbh = DBI->connect($data_source,$user,$passwd, {RaiseError => 1[......]

继续阅读

Perl用Web::Scraper抽取网页数据


用模块Web::scraper抽取指定网址的数据,它的一个好处是可以用xpath,以下只是一个简单练习而已

#!/usr/bin/perl
#Filename:sina_news.pl
#Author: lsanotes <lsanotes@gmail.com>
#Date: 03-24-2010
 
use strict;
use warnings;
use URI;
use Web::Scraper;
use utf8;
binmode(STDIN, ‘:encoding(utf8)’);
binmode(STDOUT, ‘:encoding(utf8)’);
binmode(STDERR, ‘:encoding(utf8)’);
 
my $url = "http://news.sina.com.cn/c/2010-03-24/084019930099.shtml";
my $proce = scraper {
process ‘//div[@id=&qu[......]

继续阅读