博客首页
注册
建议与交流
排行榜
加入友情链接
推荐
投诉
搜索:
帮助
好好学习
bilbo.cublog.cn
管理博客
发表文章
留言
收藏夹
· Compiler
· Unix_Linux
博客圈
音乐
相册
文章
· AutoHotKey
· C/C++
· Caml
· Perl
· Tcl & Expect
· 其他编程语言
· Visual Language
· Compiler Engineering
· Embedded System
· FieldBus
· Networking
· Hardware Desing
· Safety System
· Unix_Linux
· Software Engineering
· GSM/GSM-R
· 技术幽默
· 读书时间
· Good Resource
· 关注社会
· 胡言乱语
首页
关于作者
姓名:你知道 职业:IT 年龄:每年大一岁 位置:地球 个性介绍:挺笨 Email: bilbo0214@163.com
||
<<
>>
||
我的分类
文章列表 - Perl
(转)Net-Google with ActiveState Perl
<h1>Net-Google with ActiveState Perl</h1> <div class="remark">Installation | <a href="http://johnbokma.com/perl/net-google/comments.html">3 comments</a></div> <p class="first"> If you want to use the Google APIs via Perl, a search at CPAN wile lead you to Net-Google. However, this distribution seems not to be available for the Active State version of Perl last time I checked (March, 30th, 2004). </p> <p class="ad"> <em>You want your ad served 320,000 times a month?</em> <a href="http://johnbokma.com/advertise-your-ad-on-this-site.html">Advertise on John Bokma dot com</a> and I make it happen. </p> <p> Luckily, downloading the gzipped tar file and installing it is quite straightforward. But first you need to get a license key from Google. </p> <h2>Getting a Google APIs license key</h2> <p class="first"> A license key is required from Google in order to use the Net-Google modules. Visit the <a href="http://www.google.com/apis/">Google……
查看全文
发表于:2008-07-02 ┆
阅读(128)
┆
评论(0)
perl中调用C函数的一个例子(XS方式)
<DIV>背景:因为一个临时的工作需要,花了一天的时间写了一个小程序,在perl中调用C函数(用的是XS方式),记录如下。这个程序实现了一个定制的CRC32计算(perl的Digest::CRC有一般的CRC计算,但不适用于我的应用)。</DIV> <DIV></DIV> <DIV>前提:<BR>1. 安装了ActivePerl 5.8<BR>2. 安装了VC或Dev-C++,正确设置了环境变量 </DIV> <DIV><BR>操作过程如下: <BR>1. 在命令行下执行 <BR> > h2xs -A wldemo <BR> > cd wldemo<BR>2. 编辑文件wldemo.xs, wldemo.xs修改后的内容如下:<BR> </DIV> <DIV><PRE><CODE><EM><FONT color=#0a246a>/* CCITT crc32 perl XS implementation. Author: Wang Lei Create Date: Jan 30, 2008 Usage: use WLDEMO; my @data = (0x00, 0x00, 0x00, 0x00); WLDEMO->crc32_init(); printf("%x", WLDEMO->crc32(4, pack("C4", @data))); */ </FONT></EM><FONT color=#008000>#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #define CRCPOLY 0xEDB88320UL #define CRCINIT 0xFFFFFFFF </FONT><STRON……
查看全文
发表于:2008-01-30 ┆
阅读(561)
┆
评论(2)
simple stack machine in perl
昨天在网上查资料,偶然发现一个简单的stack machine的c++实现<br><a href="http://www.cis.rit.edu/%7Enjs8030/coding/stackMachine.C" target="_blank">http://www.cis.rit.edu/~njs8030/coding/stackMachine.C</a>,写的很简单,读了一下。<br><br>今天用perl写了一个功能相同的程序,代码如下:<br>#!perl -w <br><br>use strict;<br>use warnings;<br><br>my @funcstack = (); # function stack<br>my @valuestack = (); # value satck<br>my %funclist = ( <br> "dump" => \& dumpvaluestack,<br> "+" => \&add, <br> "-" => \&sub, <br> "*" => \&mul, <br> "/" => \&div,<br>);<br><br># Computation stack:<br># (+ 3 (* 2 9)) = 21<br>push(@funcstack, "dump");<br>push(@funcstack, "+");<br>push(@funcstack, "*");<br>push(@valuestack, 3);<br>push(@valuestack, 2);<br>push(@valuestack, 9);<br><br>interpreter(\@funcstack, \@valuestack);<br><br>#----------------stack……
查看全文
发表于:2007-10-14 ┆
阅读(577)
┆
评论(0)
用perl实现数据按位解析
主要思路来自于http://perlmonks.org/index.pl?node_id=300857,稍微修改了一下代码。<br><br>比如有如下的数据文件:<br><div align="center"><img src="http://blogimg.chinaunix.net/blog/upfile/071008230727.jpg" onload="javascript:if(this.width>500)this.width=500;" border="0"><br><br><div style="text-align: left;">图中的数据实际上是按位存储的,而且不是字节对齐的,因此用C解析起来相对困难。用perl可以方便的把位串转化称为位字符串,这样再处理字符串就容易多了。<br><br>下面是针对上面的数据的处理的程序,用到了一个自定义的package:<br>#!/usr/bin/perl<br>use yBitstream;<br><br>my %baliseheader = (<br> Q_UPDOWN => '', #1 bit<br> M_VERSION => "", # 7 bits<br> Q_MEDIA => '', # 1 bit<br> N_PIG => '', # 3 bits<br> N_TOTAL => '', # 3 bits<br> M_DUP => '', # 2 bits<br> M_MCOUNT => '', # 8 bits<br> NID_C => '', # 10 bits<br>  ……
查看全文
发表于:2007-10-08 ┆
阅读(616)
┆
评论(0)
(转)A simple cat program
<center><b><font color="#000000"><font size="+2">A simple <i><tt>cat</tt></i> program, written with Perl</font></font></b></center> <p><b><font size="+1">Introduction</font></b> </p><p>The other day I was working on a Windows95 laptop, and I really missed my good friend, the Unix <tt>cat</tt> command. I was trying to merge a bunch of files together, and couldn't think of how to do it easily on Windows system (the DOS <tt>type</tt> command certainly didn't do it). Easily distracted, I set off to write a <b><tt>cat</tt></b> command with Perl that I could use on <i>any</i> system. <br> </p><p><b><font size="+1">A little background - how <tt>cat</tt> should work</font></b> </p><p>For those who are not familiar with <a href="file:///unix/edu/examples/">Unix</a>, the <a href="file:///unix/edu/examples/cat.shtml">cat command</a> stands for <i>concatenate</i>. You can use cat to display the contents of a file named <tt>myfile</tt> by typin……
查看全文
发表于:2007-08-19 ┆
阅读(748)
┆
评论(0)
(转)perl特殊变量
<p> </p><center><font size="+3">Special Variables</font></center> <a name="toc"></a> <h3>Table of Contents</h3> <ul><li><a href="http://www.kichwa.com/quik_ref/spec_variables.html#filehandle">Per-filehandle Special Variables</a> </li><li><a href="http://www.kichwa.com/quik_ref/spec_variables.html#local">Local Special Variables</a> </li><li><a href="http://www.kichwa.com/quik_ref/spec_variables.html#global">Global Special Variables</a> </li></ul> Please bear with me while I try to complete these pages. I'll get to them when I can. <br> Cheers... <hr size="5"> <p> <a name="filehandle"></a> </p><center><table border="5" cellpadding="2" cellspacing="5" width="600"> <tbody><tr><th colspan="3">Per-filehandle Special Variables</th></tr> <tr><td colspan="3">These variables never need to be mentioned in a <b>local</b>()because they always refer to some value pertaining to the currently selected output filehandle - each filehandle keeps its own set of values.</td></tr> <tr……
查看全文
发表于:2007-08-19 ┆
阅读(760)
┆
评论(0)
使用perl分析ini文件的三种方法
画了一个上午的时间来研究如何用perl分析ini风格的文件,找到了三种方法。<br><br>第一种方法:自己编写分析程序,重新造个轮子。<br><br>#!perl -w<br># parse ini file using reinvent the wheel method<br>#<br><br>use strict;<br>use Cwd;<br><br>my $dir = getcwd; <br>my $file = $dir . $ARGV[0];<br><br>chomp($file);<br>parse_config_file ($file);<br><br><br>sub parse_config_file {<br> my ($config_line, $key, $value);<br><br> my ($File) = @_;<br> <br> open (CONFIG, "$File") or die "ERROR: Config file not found : $File";<br><br> while (<>) <br> {<br> $config_line=$_;<br> chomp ($config_line); # Get rid of the trailling \n<br> $config_line =~ s/^\s*//; # Remove spaces at the start of ……
查看全文
发表于:2007-07-21 ┆
阅读(1211)
┆
评论(0)
Perl学习资源(不断更新中...)
<BR> <HR style="WIDTH: 100%; HEIGHT: 2px"> <SPAN style="FONT-WEIGHT: bold">Perl Tutorial</SPAN><BR><BR><A href="http://www.comp.leeds.ac.uk/Perl/start.html">http://www.comp.leeds.ac.uk/Perl/start.html</A><BR><BR><A href="http://www.tizag.com/perlT/" target=_blank>http://www.tizag.com/perlT/</A><BR><BR>Perl Basics:<A href="http://www.cooperstown.com/izb/perl/index.html" target=_blank>http://www.cooperstown.com/izb/perl/index.html</A><BR><BR>Advanced Perl:<A href="http://www.cooperstown.com/izb/advperl/index.html" target=_blank>http://www.cooperstown.com/izb/advperl/index.html</A><BR><BR>Examples in Perl: <A href="http://www.motreja.com/ankur/examplesinperl/index.html" target=_blank>http://www.motreja.com/ankur/examplesinperl/index.html</A><BR><BR>Data Manipulation Using Perl: <A href="http://interoperating.info/courses/perl4data/" target=_blank>http://interoperating.info/courses/perl4data/</A><BR><BR>Little Perl: <A href="http://www.troubleshooters.com/codecorn/littperl/index.htm" t……
查看全文
发表于:2007-07-20 ┆
阅读(1088)
┆
评论(0)
最简单的代码美化器
<P>最简单的意思就是只有一个将Tab键替换为4个空格的功能,但很实用。我经常用不同的编辑器写代码,结果有时候老是忘记Tab键的问题,有时候不注意编辑器会自动加入Tab键,为了让代码在各种编辑器下显示一致,就简单写了个perl程序。<BR><BR>#!perl<BR>#<BR># simple source code beautifier<BR># replace all tab with 4 spaces.<BR>#<BR><BR>use warnings;<BR>use strict;<BR><BR>while (<>)<BR>{<BR> my $line = $_;<BR> $line =~ s/\t/ /g;<BR> print $line;<BR>}<BR><BR>perl太强大了,要是用C写需要几十条语句呢。<BR><BR>用perl2exe replaceTab.pl可以生成exe版本的程序。<BR><BR>用的时候,replaceTab [源文件] > [目标文件] </P> <P> </P> <P>---------------------------------------</P> <P>感谢网友的留言和指针,上面提到的的确不能算是最简单的。下面贴出网友推荐的另外两种更简单的方法。</P> <P><FONT color=#ff0000>sed -i 's/\t/ /g' file.c<BR></FONT></P> <P><FONT color=#ff0000>在vim中 %s/\ 注此外按ta……
查看全文
发表于:2007-07-09 ┆
阅读(1692)
┆
评论(6)
perl PAR安装问题解决
今天偶然看到论坛上有人问perl生成exe的问题,就在网上搜了一下,发现不仅仅是perl2exe一种方法,还可以使用par来生成,就自己试验了一下,不过par安装不是很容易,花了一个多小时才把它搞定,记录下来备忘。<br><br>第一步:ppm install par<br>这个比较简单,当然如果幸运的话,你应该可以直接使用par了,但是我没有那么幸运,因为安装之后找不到pp.bat,实际上这是ActivePerl的问题,没办法只能往下继续了。<br><br>第二步:重新安装par-packer<br>不过之前要更新一个模块File-Temp,我原来的版本是0.12,太低,换成0.18的<br><code> ppm install http://www.bribes.org/perl/ppm/File-Temp.ppd<br>然后安装par-packer 0.975<br></code><code>ppm install http://www.bribes.org/perl/ppm/PAR-Packer.ppd<br><br>第三步:这时已经可以使用pp.bat了,但是你会发现pp不能生成exe文件,总是报<br>erl lib version (v5.8.8) doesn't match executable version (v5.8.6)的错误,<br>原因在于二进制不兼容,需要继续修改。<br><br>第四步:下载5.8.8的par-packer<br>http://www.perl.com/CPAN/authors/id/S/SM/SMUELLER/PAR-Packer-0.975-MSWin32-x86-multi-thread-5.8.8.pa……
查看全文
发表于:2007-07-07 ┆
阅读(1141)
┆
评论(2)
2 perl online classes
找到两个perl的课程,可以下载ppt讲义。<br><br>初级:http://www.cooperstown.com/izb/perl/index.html<br><br>高级:http://www.cooperstown.com/izb/advperl/index.html<br>
查看全文
发表于:2007-06-23 ┆
阅读(732)
┆
评论(0)
推荐一个perl初学者的教程
<DIV>看上去还不错。</DIV> <DIV><A href="http://www.comp.leeds.ac.uk/Perl/start.html">http://www.comp.leeds.ac.uk/Perl/start.html</A></DIV>
查看全文
发表于:2007-06-12 ┆
阅读(779)
┆
评论(0)
增强版的ExecLog(perl/win32::GUI)
<div align="center"><div style="text-align: left;">增强版本的execlog.pl,增加了保存日志记录到文件的功能。<br></div><img src="http://blogimg.chinaunix.net/blog/upfile/070608230021.jpg" onload="javascript:if(this.width>500)this.width=500;" border="0"><br><div style="text-align: left;"><br>源代码如下:<br></div><div style="text-align: left;">#!perl -w<br><br># execlog - run a program with exec and log the output<br># perl/win32::GUI implementation<br><br>use strict;<br>use warnings;<br>use threads;<br>use Net::PcapUtils;<br>use Win32::GUI qw( MB_ICONQUESTION MB_ICONINFORMATION MB_YESNOCANCEL<br> MB_OK IDYES IDCANCEL );<br> <br>#create menu<br>my @menu_defn = (<br> "&File" => "File",<br> " > -" &nb……
查看全文
发表于:2007-06-08 ┆
阅读(985)
┆
评论(0)
windows下简单的ExecLog程序(perl vs. tcl/tk)
在网上看到过一个TCL写的记录程序执行结果的小程序,用perl实现的一个类似功能的程序。就是在一个行编辑器中输入要执行的程序名,然后单击“运行”按钮,执行结果将显示在下面的记录框内。界面如下:<br><div align="center">perl程序界面<br><img src="http://blogimg.chinaunix.net/blog/upfile/070608222947.jpg" onload="javascript:if(this.width>500)this.width=500;" border="0"><br>tcl程序界面<br><div align="center"><img src="http://blogimg.chinaunix.net/blog/upfile/070608223001.jpg" onload="javascript:if(this.width>500)this.width=500;" border="0"></div></div><br><br>源代码为:<br><table style="border-collapse: collapse;" align="center" border="1" bordercolor="#dddddd" cellpadding="0" cellspacing="0" width="360"> <tbody><tr height="60"><td align="center" width="60"><img src="/fileicon/rar.gif" alt="" border="0"></td><td> <table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr height="20"><td align="center" width="40">文件:</td><td>ExecLog.rar</td></……
查看全文
发表于:2007-06-08 ┆
阅读(906)
┆
评论(0)
perl中qx/STRING/用法
# qx/STRING/<br># `STRING`<br><br><b>A string which is (possibly) interpolated and then executed as a system command with /bin/sh or its equivalent.</b> Shell wildcards, pipes, and redirections will be honored. The collected standard output of the command is returned; standard error is unaffected. In scalar context, it comes back as a single (potentially multi-line) string, or undef if the command failed. In list context, returns a list of lines (however you've defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.
查看全文
发表于:2007-06-06 ┆
阅读(984)
┆
评论(0)
安装perl模块的一个好去处
比较了一下还是 http://www.bribes.org/perl/ppmdir.html 这个网站好,如果没有代理的限制,直接从网络上安全PPM格式的各种模块非常方便,比从ActivatePerl的网站上下载容易多了。<br><br>我比较喜欢PPM的格式,因为不需要其他编译的支持,比如从CPAN下载的Win32::API就需要VC中的cl.exe,前几天下的Inline模块甚至在运行过程中都需要cl.exe,晕死了。<br>
查看全文
发表于:2007-05-23 ┆
阅读(773)
┆
评论(0)
Windows下简单网络dumper程序(perl Win32 GUI实现)
<DIV>正在学习Perl的Win32::GUI,在网络上看到有人写了一篇“使用Perl编写协议分析脚本”的文章,就试着改了改加了一个GUI的界面,主要目的还是熟悉Win32::GUI中的一些控件。</DIV> <DIV> </DIV> <DIV>这个程序还有很多bug,欢迎扔鸡蛋。</DIV> <DIV> </DIV> <DIV>下面是程序的主要界面。</DIV> <DIV> <DIV align=center><IMG src="http://blogimg.chinaunix.net/blog/upfile/070516124738.jpg" onload="javascript:if(this.width>500)this.width=500;" border=0></DIV></DIV> <DIV> </DIV> <DIV>程序源代码包为:</DIV> <DIV> <TABLE style="BORDER-COLLAPSE: collapse" borderColor=#dddddd cellSpacing=0 cellPadding=0 width=360 align=center border=1> <TBODY> <TR height=60> <TD align=middle width=60><IMG alt="" src="http://control.cublog.cn/fileicon/rar.gif" border=0></TD> <TD> <TABLE style="BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width="100%" border=0> <TBODY> <TR height=20> <TD align=middle width=40>文件:</TD> <TD>netdump.rar</TD></TR> <TR height=20> <TD align=middle width=40>大小……
查看全文
发表于:2007-05-16 ┆
阅读(831)
┆
评论(0)
安装perl Win32::GUI
从sourceforget下载Win32-GUI-1.05-PPM-5.8.zip,因为我的机器装的是ActivePerl,所以用PPM安装比较方便。<br><br>先将这个zip文件解压到一个临时目录,比如E:\ttt<br>在dos命令行下运行ppm,界面如下:<br><div align="center"><img src="http://blogimg.chinaunix.net/blog/upfile/070508214152.jpg" onload="javascript:if(this.width>500)this.width=500;" border="0"></div><br>然后执行install e:\ttt\Win32-GUI.ppd就行了。<br><br>装完以后运行一个测试程序,但出现下面的提示:<br><div align="center"><img src="http://blogimg.chinaunix.net/blog/upfile/070508214501.jpg" onload="javascript:if(this.width>500)this.width=500;" border="0"></div><br><br>在网络上搜了半天才知道是由于perl版本的问题。<br>我的perl版本是:<br><br>This is perl, v5.8.8 built for MSWin32-x86-multi-thread<br>(with 21 registered patches, see perl -V for more detail)<br><br>Copyright 1987-2006, Larry Wall<br><br>Binary build 816 [255195] provided by ActiveState http://www.ActiveState.com<br>Built Mar 1 2006 18:00:52<br><br>Win32::GUI 1.05版本好像……
查看全文
发表于:2007-05-08 ┆
阅读(1116)
┆
评论(0)
perl写二进制文件要用pack
<DIV>以前用过又忘记了,写下来留着备忘。</DIV> <DIV> </DIV> <DIV>下面是一个非常简单的读文本写二进制的例子,从一个文本文件中读入数字,然后转成二进制存储。</DIV> <DIV>例如:文本文件以空格分隔存放90 12 0b,二进制文件按顺序存放90 12 0b</DIV> <DIV> </DIV> <DIV>#!perl -w<BR>#<BR># Usage: convert.pl [source file] [destination file]<BR># If we donot provide source file, STDIN will be used as source.<BR># If we donot provide destination file, a file named a.out will be used as output.</DIV> <DIV>if ($#ARGV != 1) <BR>{<BR> print "Use a.out as default output file.\n";<BR> $destfile = "a.out";<BR>}<BR>else<BR>{<BR> $destfile = $ARGV[1]; #using user defined output file<BR>}</DIV> <DIV>open OUTF, ">$destfile" or die "Can't open $destfile for writing!\n";</DIV> <DIV>binmode(OUTF);</DIV> <DIV>while (<>) <BR>{<BR> for $chunk (split(/ /, $_)) <BR> {<BR>……
查看全文
发表于:2007-04-28 ┆
阅读(1271)
┆
评论(0)
A bug in my perl program
<DIV>昨天上网后用自己写的时间统计程序进行统计,结果发现时间竟然没有增加。</DIV> <DIV>查看系统事件是有记载的,但为什么程序无法读处理呢?</DIV> <DIV>我分析错误发生在读取事件的代码中,没办法只有一点一点调试。</DIV> <DIV> </DIV> <DIV>先是显示出$number的值,然后显示每个事件内容。</DIV> <DIV>发现$number与系统记录的个数是一致的,但读出来以后总是将开始的几十个给丢掉了。</DIV> <DIV>我的代码结构就是下面这个样子,并不复杂。</DIV> <DIV>$EventLog->GetNumber($number)|| die $!;<BR>$EventLog->GetOldest($first) || die $!;</DIV> <DIV> </DIV> <DIV>for (my $i = $number; $i > $first; $i--)<BR>{</DIV> <DIV>....</DIV> <DIV>}</DIV> <DIV> </DIV> <DIV>我又读了perl关于Win32::EventLog的文档,还是找不到头绪,偶然发现$first并不是0,以前也知道,因为其后是一些无效的事件,都是1970-1-1日期。我猜想是$number的含义理解错了,它表示的有效事件数,而不是</DIV> <DIV>第一个事件的编号,实际上第一个事件的编号应该是:</DIV> <DIV>$number + $first</DIV> <DIV> </DIV> <DIV>我加入了一段代码……
查看全文
发表于:2007-01-31 ┆
阅读(960)
┆
评论(0)