51CTO博客开发张宇(数据恢复)捕风的鱼sery《Java程序员,上班那点事儿》的那点事儿一代小怪追大怪凝固瞬间
在解析数组引用的时候, 如果括号里面是简单标量,我们可以去掉当中的大括号. 还有另外一些实用技巧,让引用显得更漂亮。
正式进入主题,perl之所以受欢迎,主要有赖于两大利器: 强大的正则表达式支持 & 强大的复杂数据结构。 复杂数据结构有赖于引用这个重要的实现方式,接下来的几篇笔记将重点讨论列表引用、哈希引用和函数(也叫子程序)引用。此外还有文件(目录)句柄引用和正则表达式引用,将在后续笔记简略讨论。
《中级perl》主要讲引用、复杂数据结构、面向对象以及如何写出中等规模的perl程序,另外还介绍了很多关于构件模块的内容。进入《中级perl》之前,先巩固一下必要的预备知识。
'last' can stop loop immediately, when you see 'last', the loop is over. while(<STDIN>){ if(/__END__/){ last; }elsif(/fred/){ print; }}## last jumps to here &n
unless expression: when condition is false execute the block. unless($fred=~/^[A-Z_]\w*$/i){ print "The value of \$fred doesn't look like a perl identifier name.\n";} It's the s
By default m// handles single line, even if some line containes \n in the line. The ^ $ symbols means the start and end to the whole characters, no matter it's a single line or multiple lines.
split can create list from given string, the format is:@fields=split /separtor/, $string; The 'separtor' usually are : or space, and it can be any other charactar/symbol. @fields=spl
s/// is the most common expression using RE to do "search and replace". s/patten/replace/ searches the 'patten' and replaces it to 'replace'. 'patten' is the patten we talked in perl
Variable can be inserted in /patten/, similar to "$variable" #!/usr/bin/perlmy $what="fred"; while(<>){ if(/^($what)/){ print "We saw $what in beginning of $_"; }} &nbs
/patten/ is a default style of RE, it's actually m/patten/.Only use / the 'm' can be missing, otherwise 'm' must be there. m{patten}m|patten|m(patten)m[patten]m#patten#m*patten*m%patten% &nb
Another good feature of Perl is RE, PerlRE. In Perl, RE usually means patten, a match (or unmatch) of some characters template. The patten can divide any characters into two parts: match and unmatch
Subroutine &keys() and &values() ruturns the keys and values of a hash.#!/usr/bin/perlmy %hash=("a"=>1,"b"=>2,"c"=>3,);my @k=keys %hash;my @v=values %hash;my $count=keys %hash;print "
Hash is the one that makes Perl one of the most popular programer languages.It's another data structure similar to array. Hash is indexed by keys, each key is an uniq characters but not numbe
printf is powerer to control the outputs, it's used with a format string, and a list of elements. printf "Hello, $s; your password expires in %d days!\n", $user, $days_to_die;printf "in %d da
InPut and Output <STDIN> can get user's input, in scalar context it returns the next line. $line=<STDIN>;chomp($line); chomp($line=<STDIN>) # same as above tw
The better &max subroutine that don't care about arguments' number. $maximum=&max(3,5,10,4,6); sub max{ my($max_so_far)=shift @_; foreach(@_){&nbs
In Perl Subroutines are the functions that user defines, Functions mean the buildin functions Perl designs.Like chomp(), reverse(), sort() and print(), they are functions. Keyword 'sub' is us
reverse() & sort() reverse() returns reversed list. @fred=6 .. 10;@barney=reverse(@fred); # got (10, 9, 8, 7, 6)@wilma=reverse 6 .. 10; # same as above@fred
pop() & push() pop() get the last element out of array, and returns that element. @array=5..9;$fred=pop(@array); # $fred is 9, @array now is (5, 6, 7, 8)$barney=pop @array;&
List & Array While scalar is single value, list is a list of scalars in order. Every element of a list is a dependant scalar, it can be number or characters. Array is the variable of lis
Like other programing languages, Perl has if() and while() to perform judgement and loop. if(condition){ do something if condition is true; }else{ &nb
I bought <<Learning Perl>> last year, but just learned to know the surface of what Perl is. One year back, I'll pick it up for second round hoping to catch up the step that QQ gr
This morning, there's an issue reported by Support team that one of our envirenments is unavailable. Just recording the steps I took to resolve the issue. Step #1: Check application
A problem happens when I ran "rpm -ivh xxxx.rpm" or "rpm -qa | grep xxx"The rpm command didn't give any output, looks like there's no response, it's called "rpm deadlock"To resolve this issue, we shou
perl script for generating secure password
simple useful perl functions
You are enrolled in a full time school called life. Each day in this school you will lear lessons; you may like the lessons or hate them, but you have designed them as part of your
I've not written blogs for very long time since 2009. I found English is more and more important for our jobs, so I decided to write all blogs in it. Recently I'
几个简单的shell脚本,分享一下
Copyright © 2005-2023 51CTO.COM 版权所有 京ICP证060544号