Archive for the ‘Perl’ Category

September 14, 2007

This is a test post from vimpress.

[Perl Learning]: Consider Perl as a tool instead of a programming language

March 2, 2007

Perl vs Python(or some other similiar language) is just like Vim vs Emacs, it is painful to choose which one to learn. Both are very powerful and have tons of fans. At first, I had no idea which one is suitable for my requirement. The first day I think Perl is compact and powerful; The second day, I think the codes written in Python are more readable.

After I hesitated for several days between them, I chose Python in the end. But I still had a problem that I don’t want to refuse Perl since some features of Perl is really cool: the syntax is compact, powerful and CPAN is very good. In fact, I want to use Perl to do small daily tasks, especially in terminal. Yes! Use Perl as a tool, just like sed,awk,grep, instead of programming language! A powerful and complete tool that includes complete data structure, powerful(maybe the most powerful) regular expression, many functions, lots of modules etc.

After thinking it clear, I can not feel better now! 😉

Enjoy powerful tools!

[Perl Learning]: A wonderful book for perl one-liner

March 2, 2007

“””
/START REGEX/ .. /STOP REGEX/ and print ;
Prints all records between the first containing “START REGEX” and the first containing “STOP REGEX” (which could be the same record), and then repeats that process, looking for the next record containing “START REGEX”, etc.

/START REGEX/ … /STOP REGEX/ and print ;
Same as the two-dot form, except the first evaluation of STOP REGEX doesn’t occur until after the record that yielded True for START REGEX has already been processed, thereby preventing both patterns from mathing the same record.
“””
for example:
$ perl -w -nle ‘/Oct 19/ … /Oct 20/ and print ‘

Above texts comes from Book <>, that is a really good book for me. It focuses on use perl to replace other legacy Unix command like grep, sed, awk etc. It describes perl one-liner in details, that is just the way which I want to use perl in.

Strongly recommended! 😉

[Perl Learning]: use single quote always

March 2, 2007

When use one-liner perl command , use single quote always.
Because when you use double quote, the commands within double quote will be expanded by shell first, most of the time, that is NOT what I want. And the worst thing is it is not easy to find out sometimes. So use singel quote always.

[Perl Learning]: pay attention to s/…/…/ trap

March 2, 2007

perl command s/…/…/ will return how many thing has been replaced but not the result after replacement, it is very different from what sed does.

$ echo a b c | perl -w -nle ‘print s/a/aa/’
will return 1

do it this way:
$ echo a b c | perl -w -nle ‘s/a/aa and print’
aa b c