1.
chmop ($ line = <STDIN>); # reads the next line, line breaks amputated.
2.
while(defined($line=<STDIN>) {
print " $_ ”;
}
3.
while(<STDIN>) {
print ”$_";
}
Equivalent to
while(defined($_ = <STDIN>) {
print " $_";
}
4. Diamond operators <> when the line input operator exception. Do not get input from the keyboard, but the user specified location.
$ ./my_programe fred barney betty
while (defined($line =< >) {
chomp($line);
print ""
}
Equivalent to
while(<>) {
chomp;
print " $_";
}
5. call parameters
<> Does this by examining the command line parameters and their array from a particular array @ARGV #Perl interpreter previously established.
@ARGV = qw /a b c d/;
while (< > ) {
chomp;
print "$_ in some stooge-like file !";
}
6. to standard output
print @C #abcd
print "@C" #abcd spaces
First output of the program buffer general, accumulate up, and then visit the large external device.
print <> # is equivalent to a Unix cat
print sort <> # sort of equivalent Unix
printf format output. And similar C language.
7. Open the file handle.
The default file handle Perl provides: STDIN STDOUT STDERR
Other handles, the use of open operator tells Perl
open CONFIG, 'dino' # open file dino, reading from the handle CONFIG
open CONFIG, '<dino' # <read-only
open CONFIG, '> fred' # open file handle CONFIG, and enter into a new file fred.
open CONFIG, '>> fred' # additional type open, if there is fred then added at the end, if there is, it is created and then written.
my $selected_output = 'my_output';
my $sucess = open LOG , "> $selected_output";
if (! $sucess) {
#
}
8. Close the handle close LOG
9.die deal a fatal error
0 sucess
1 syntax error
2 error occurred while processing program
3 can not find a profile
if (!open LOG,'>>' ,'logfile') {
die "can not create logfie: $!" # $! It refers to a system-readable error messages, such as permission denied / file not find
}
Die Perl program automatically displays the name and line number;
If you do not want to show at the end add \ n newline.
if(@ARGV < 2) {
Die "Not enough argumeng \ the n- " # do not show program name and line number
}
10. Change the default file handle
select BD
$ | = 1; # flushed immediately, without going through the buffer cache.
print BD " i hope this will come true!“