文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>perl函数

perl函数

时间:2007-09-13  来源:jackliy

其他编程语言 > perl 函数集
【标  题】:perl 函数集
【关键字】:perl
【来  源】:http://www.cublog.cn/u/8780/showart.php?id=181428

perl 函数集

perl的主站---函数的帮助资料。
http://www.perldoc.com/perl5.6/pod/perlfunc.html

网上资源:
http://member.netease.com/~elvis/docs/c11.htm
http://www.panjin.net/tybl/cgi/jiaocheng/cp3.htm
http://www.mstong.net/yehuo/tanshow....12&filename=55
http://www.mamiyami.com/doc/php/ref.strings.html

一些函数的解释


abs

PHP 代码:
#!/usr/bin/perl -w
#$result=abs(value);
#
@re=abs(-23);
print "\@re\=abs\(\-23\)\;\n";
print "\@re\=@re\n";


array

PHP 代码:
#!/usr/bin/perl -w
@num=qw(11 33 2 dd 0);
printf "first:@num\n";
$name="dear";
@list=(1..12,"hello",$name,"hello $name",4+6,1-2,2*3);
printf "second:@list\n";
@a=(a..z,A..Z,-2.3..8.1);
printf "three:@a\n";
printf "four:next\n";
@b=(1,"world",@num);
printf "third@b\n";
printf "sixnext\n";
@c=@num;
printf "sevre@c\n";


atan2

PHP 代码:
#!/usr/bin/perl -w
#retval=atan2(value1,value2);
#
sub degress_to_radians {
my ($degress) = @_;
my ($radians);11;
$radians = atan2(1,1) * $degress /45;
}


chdir

PHP 代码:
#!/usr/bin/perl -w
#change the current directory .
chdir("/root");
$result=system("ls");
print "$result\n";


chomp AND chop

PHP 代码:
#!/usr/bin/perl -w
use strict;
my @a="abcd";
print "@a\n--chomp--\n";
chomp(@a);
print "@a\n";
print "---chop---\n";
my @b="uiok";
print "@b\n";
chop(@b);
print "@b\n";


chr

PHP 代码:
#!/usr/bin/perl -w
#@char=chr(asciivalue);
#
@a=chr(97);
print "@a\n";


each

PHP 代码:
#!/usr/bin/perl -w
#@pair=each(%assoc_array);
#
print "\@pair\=each\(\%assoc\_array\)\;\n";
%array=(9,"first",2,"second");
@a=each(%array);
print "@a\n";

%arrayA=(8,"first",6,"second");
@b=each(%arrayA);
print "@b\n";

%arrayB=(12,"first",98,"second",66,"three",2,"found");
@d=each(%arrayB);
@e=each(%arrayB);
@f=each(%arrayB);
print "@d\n@e\n@f\n";


eof

PHP 代码:
#!/usr/bin/perl -w
while ($line = <>) {
   print ($line);
   if (eof) {
   print ("-- end of current file --\n");
}
}


eval

PHP 代码:
#!/usr/bin/perl -w
$print="print (\"hello,world\\n\");";
eval ($print);
#run as perl command.


foreach

PHP 代码:
#!/usr/bin/perl -w
@array=("how","do","you","do" , "fine");
foreach $a(@array){
$a=~s/o/CHANGE/;
print "$a\n";
};
#
open (FILE, "test03.pl" );
foreach (<FILE> ) {
print "$_";
}


fork

PHP 代码:
#!/usr/bin/perl -w
$result=fork();
if($result == 0) {
                 #this is the child process
exit; #this is terminates the child process
}else{
#this is the parent process
}


forka

PHP 代码:
#!/usr/bin/perl -w
$child=fork();
print "$child\n";


format

PHP 代码:
#!/usr/bin/perl -w
#file :format
#
$~="myformat";
write;
format myformat=
========================
hello,the world!
========================
.


getc AND die

PHP 代码:
#!/usr/bin/perl -w
open(FILE,"/etc/fstab") or die "could not open /etc/fstab:$!";
print (getc(FILE),"");
$a=getc(FILE);
#chomp($a);
print "$a";
print (getc(FILE));
print (getc(FILE)."\n");


grep

PHP 代码:
#!/usr/bin/perl -w
#@foundlist = grep (pattern, @searchlist);
#
@list = ("This", "is", "a", "test");
@foundlist = grep(/^[tT]/, @list);
print "@list\n@foundlist\n";
#
#result:::
#This is a test
#This test


hash

引用:
#!/usr/bin/perl -w
%a=(1,"a",2,"b",3,"c",4,"d",5,"e",6,"f");
$b=$a{1}; print "$b\n";
#
$a{2}="change"; $b=$a{2}; print "$b\n";
#
@index=keys(%a); print "@index\n";
#
@content=values(%a); print "@content\n";
#
@d=%a; print "@d\n";
#
delete $a{5}; @d=%a; print "@d\n";
#
$i="a"; $j=1; delete ${$i}{$j}; @d=%a; print "@d\n";


hex

PHP 代码:
#!/usr/bin/perl -w
#16 format to 10 format number.
#result=hex(16 format);
#
@a=hex(032);
print "@a\n";


index

PHP 代码:
#!/usr/bin/perl -w
#position=index(string,substring,position);
#
@re=index("1234567","123");
print "@re\n";
@re=index("1234567","6","3");
print "@re\n";


int

PHP 代码:
#!/usr/bin/perl -w
@a=int(2.39);
print "@a\n";


join

PHP 代码:
#!/usr/bin/perl -w
#join (joinstr,list);
#
@a=("a","b","c","d");
print "@a\n";
@b=join("#",@a);
print "@b\n";


keys

PHP 代码:
#!/usr/bin/perl -w
#@list=keys(%assoc_array);
%NAME=(1,"mike",2,"michael");
@readkey=keys(%NAME);
print "%NAME\n";
print "@readkey\n";


kill

PHP 代码:
#!/usr/bin/perl -w
#kill(signal,proclist);
#signal == signal ;example 9
#porclist == process ID
kill (9,1617);


last

PHP 代码:
#!/usr/bin/perl -w
$a=12;
print "\$a\=$a\n";
while($a<25) {
$a++;
last if ($a == 20);
print "$a ";
}
print "\n";


lc

PHP 代码:
#!/usr/bin/perl -w
@a=lc("ABC");
print "@a\n";


lcfirst

PHP 代码:
#!/usr/bin/perl -w
#
# result=lcfirst(string);
@result=lcfirst("abcdefg");
print "@result\n";
@a=lcfirst("ABCD");
print "@a\n";


length

PHP 代码:
#!/usr/bin/perl -w
#num=length(string);
#
@num=length("abcdefg");
print "@num\n";


log

PHP 代码:
#!/usr/bin/perl -w
#result=log(value);
#
$re=log(12);
print "\$re\=log\(12\)\;\n";
print "\$re\=$re\n";


map

PHP 代码:
#!/usr/bin/perl -w
#@resultlist=map(expr,@list);
#
@list=(50,3,1000);
print "@list\n";
@result=map($_+1,@list);
print "@result\n";
print "@list\n";


mkdir

PHP 代码:
#!/usr/bin/perl -w
#4000: running setup user ID.
#2000: running setup groupp ID.
#1000: ease.
#0400: readable with own.
#0200: write with own.
#0200: can running with own.
#0040: readable group.
#0020: can write with group.
#0010: can running with group.
#0004: readable with all user.
#0002: write with all user.
#0001; running with all user.

mkdir("aka",0777) or die "Could not creat directory\n";


next

PHP 代码:
#!/usr/bin/perl -w
$a=18;
while($a<23){
$a++;
next if ($a==20);
print "$a ";
}
print "$a\n";


oct

PHP 代码:
#!/usr/bin/perl -w
#8 OR 16 format to 10 format
#@result=oct(octnum);
#
@a=oct("013");
print "@a\n";
@b=oct("0x1a");
print "@b\n";


opendir ADN readdir AND closedir

PHP 代码:
#!/usr/bin/perl -w
opendir (DIR,"/root") or die "could not open /root";
@dots=grep {/^[^.]/ && -d "/root/$_" } readdir(DIR);
foreach (@dots) {
print "$_\n";
}
closedir DIR;


ord

PHP 代码:
#!/usr/bin/perl -w
#@result=ord("char");
#print a character ASCII value.
#
use strict;
my @a=ord("a");
print "@a\n";


pipe

PHP 代码:
#!/usr/bin/perl -w
pipe(INPUT,OUTPUT);
$result=fork();
if($result != 0){
#this is cht parent process.
close(INPUT);
print("Enter a line of input:\n");
$line=<>;
print OUTPUT ($line);
}else{
#this is the child process.
close (OUTPUT);
$line=<>;
print($line);
exit(0);
}
#pipe as shell " | ".


pop

PHP 代码:
#!/usr/bin/perl -w
#@element=pop(@array);
#
@array=("hello","the","world","dear");
print "@array\n";
@element=pop(@array);
print "@array\n@element\n";


push

PHP 代码:
#!/usr/bin/perl -w
#push(@arrayvar,elements);
#
@array=("hello","free","world");
print "@array\n";
push(@array,"my dear");
print "@array\n";
push(@array,"my dear too");
print "@array\n";


redo

PHP 代码:
#!/usr/bin/perl -w
$a=15;
while ($a<19){
$a++;
print "$a ";
redo if ($a ==19);
}
print "\n";

$a=15;
while($a<=19){
$a++;
print "$a ";
redo if ($a ==19);
}
print "\n";


reverse

PHP 代码:
#!/usr/bin/perl -w
use strict;
print "Enter the list of string:\n";
my $a=0;
my $into;
my @test;
while ( $a<6) {
chomp($into=<>);
unshift(@test,"$into");
$a++ ;
}
print "@test\n" ;
#
my @reverse=reverse(@test);
print "@reverse\n ";
my @b;
@b=reverse("a","b","c","d");
print "@b\n";


rindex

PHP 代码:
#!/usr/bin/perl -w
#position =rindex(string,substring.position);
#from right to left
#
@a=rindex("abcdefg","e","b");
print "@a\n";
@a=rindex("abcdefg","e");
print "@a\n";


shift

PHP 代码:
#!/usr/bin/perl -w
#element = shift (@arrayvar);
#
@array=("a","998","ojjo","iu");
print "@array\n";
@a=shift(@array);
print "@array\n@a\n";


shutdown

引用:
#Shuts down a socket connection in the manner indicated by HOW, which has the
#same interpretation as in the system call of the same name.
shutdown(SOCKET, 0); # I/we have stopped reading data
shutdown(SOCKET, 1); # I/we have stopped writing data
shutdown(SOCKET, 2); # I/we have stopped using this socket


sleep

PHP 代码:
#!/usr/bin/perl -w
@a=sleep (3);
print ("the process alerady sleep 3 second\n");
print "@a\n";
print ("return value is NULL\n");

print "\n";


sort

PHP 代码:
#!/usr/bin/perl -w
@a=sort("a","b",1,3,6,0);
print "@a\n";


splice

PHP 代码:
#!/usr/bin/perl -w
#@retval = splice (@array, slipelements, length, @newlist);
#if lenth=0;then insert a element.
#
@array=("a","b","9","8","K","ok");
@a=splice (@array, 2, 2, "Hello");
print "@a\n";


split

PHP 代码:
#!/usr/bin/perl -w
#@list=split(parrern,sting,maxlength);
#
@text=("well","hello,the world","how","do","you","do");
print "@text\n";
@name=split(/,/,@text,2);
print "@name\n";
print "@text\n";
$abc = "apile:fjkdfk:300:500:XXX:/bin/bash";

@abc = split(/:/,$abc);
print "@abc\n";


sprintf

PHP 代码:
#!/usr/bin/perl -w
#same like printf ,not ouput to file,return value to variable .
#
$num=26;
$outstr=sprintf("%d=%x hexadecimal or %o octal\n",$num,$num,$num);
print ($outstr);


sqrt

PHP 代码:
#!/usr/bin/perl -w
#retval=sqrt(value);
#example
#value > 0;
$result=sqrt(9);
print "\$result\=sqrt\(9\)\;\n\$result\=$result\n";


srand AND rand

PHP 代码:
#!/usr/bin/perl -w
#result=rand(num);
#
srand();
$re=rand(A);
print "$re\n";


system

PHP 代码:
#!/usr/bin/perl -w
#system() ;run a shell commend.

$result=system "date";
$see=system("ls","/root");
print "$result\n";
print "$see\n";
$well=system "'date'";
print "$well\n";
@hello=("echo","hello,world!");
system(@hello);


uc

PHP 代码:
#!/usr/bin/perl -w
@a=uc("abcd");
print "@a\n";


unless

PHP 代码:
#!/usr/bin/perl -w
$a=12;
unless ($a!=12){
print "first:$a\n";
}
unless($a==12){
print "second:$a\n";
}


unlink

PHP 代码:
#!/usr/bin/perl -w
#unlink("filename");
unlink("/share/perl/test");


unpack

PHP 代码:
#!/usr/bin/perl -w
#@list = unpack (packformat, formatstr);
#
open (CODEDFILE, "/share/perl/function/aa") ||
die "Can't open input file";
open (OUTFILE, ">outfile") ||
die "Can't open output file";
while ($line = <CODEDFILE>) {
$decoded = unpack("u", $line);
print OUTFILE ($decoded);
}
close (OUTFILE);
close (CODEDFILE);


unshift

PHP 代码:
#!/usr/bin/perl -w
#count = unshift (@arrayver, elements);
#
@array=("ui","ok","nb","li","well");
print "@array\n";
@a=unshift(@array,"first");
print "@array\n@a\n";


until

PHP 代码:
#!/usr/bin/perl -w
$a=12;
until ( $a==18) {
$a++;
print "$a ";
}
print "\n";


values

PHP 代码:
#!/usr/bin/perl -w
#@list=values(%assoc_array);
#
print "\@list\=values\(\%assoc\_array\)\;\n";
%NAME=(1,"mike",2,"michael");
@readval=values(%NAME);
print "@readval\n";



vec

PHP 代码:
#!/usr/bin/perl -w
#retval = vec (vector, index, bits);
#
$vector = pack ("B*", "11010011");
$val1 = vec ($vector, 0, 4);
$val2 = vec ($vector, 1, 4);
print ("high-to-low order values: $val1 and $val2\n");
$vector = pack ("b*", "11010011");
$val1 = vec ($vector, 0, 4);
$val2 = vec ($vector, 1, 4);
print ("low-to-high order values: $val1 and $val2\n");


waitpid

PHP 代码:
#!/usr/bin/perl -w
#wait for a sub_process,unit the sub_process done.
#procid is ID of sub_process
#format : waitpid(procid,witflay);
#example:
$procid=fork();
if ($procid == 0){
#this is the child porcess
print ("this line is printed first\n");
exit(0);
}else{
#this is the parent process
waitpid($procid,0);
print ("this line is printed last\n");
}


wantarray

PHP 代码:
#!/usr/bin/perl -w
#result=wantarray();

@array = &mysub();
$scalar = &mysub();

sub mysub {
    if (wantarray()) {
       print ("true\n");
     } else {
     print ("false\n");
     }
}


while

PHP 代码:
#!/usr/bin/perl -w
use strict;
open(FILE, "/etc/fstab" );
my $line;
while ( $line=<FILE>) {
print "$line";
}


umask

PHP 代码:
umask(0111);
排行榜 更多 +
打螺丝高手

打螺丝高手

模拟经营 下载
解救火柴人计划安卓版

解救火柴人计划安卓版

体育竞技 下载
鸡生化精英安卓版

鸡生化精英安卓版

飞行射击 下载