#!/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
}
#!/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
#!/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 " | ".
#!/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";
#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");
#!/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);
#!/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);
#!/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";
}