Common Symbols and Operations in Perl

Notes:

1. Single line: #print
2. Multiple lines: =pod .... =cut

Query perl related:

Perldoc perlvar($a,$$,$”...)
Perldoc perfunc(sort...)
Perldoc perl View perldoc article list
Perldoc –q Regular expression
Perldoc –f Function name
Perldoc module_name View module
Perldoc –v Variable name View variable
Perldoc perlop View Operators

View module-related functions:

1.Perl –d –e 0
2.Use module::submod
3.S module::submod

Test program running time:

1. Under Unix: Time perl5 perl_program
2. Add in the program: $end_time = time(); $elapsed_time = $^T - $end_time; print $elapsed_time;
3. Use the benchmark module in the perl program: use benchmark; timestamp1 = new benchmark; {Code};timesamp2 = new benchmark; time_run = timediff(timestamp2 - timesamp1);

symbol:

<=> Spaceship operator, spaceship operator: a three-way comparison number operator. $a<=>$b This operator compares two numbers and returns -1,0,1. Return 1: $a>$b, return 0: $a=$b, return -1: $a<$b.
When used in sort, $a, $b represent the first and second incoming scalars or arrays, etc.
$! Return an error number or error string according to the context
$" list separator
$# The default digital output format when printing numbers
$$ The process ID of the Perl interpreter
$% The current page number of the current output channel
$& The string matching the previous format
$(The group ID of the current process$) The effective group ID of the current process
$* Set 1 to process multiple lines Format. Now it is mostly replaced by /s and /m modifiers.
$, the current output field separator
$. The current input line number of the file read last time
$/ The current input record separator, the default is a new line
$: character Set, strings after this will be split to fill consecutive fields.
$; Delimiter used when simulating multidimensional arrays.
$? Returns the status of the last external command
$@ The error message returned by the Perl interpreter from the eval statement
$ [index number of the first element in the array
$\ delimiter of the current output record
$] subversion number of the Perl interpreter
$^ output format name of the top page of the current channel
$^A used to save formatted data before printing Variable
$^D Value of debug flags
$^E Operating system extended error messages in non-UNIX environments
$^F Maximum file descriptor value
$^H Syntax checking status activated by the compiler
$^I Built-in control editor value
$^L Form feed sent to the output channel
$^M Spare memory pool Size
$^O Operating system name
$^P Internal variable specifying the current debug value
$^R The last evaluation result of the regular expression block
$^S Current interpreter state
$^T Counting from the beginning of the new century, the script is in seconds Computed start time
$^V perl version
$^W current value of the warning switch
$^X name of the Perl binary executable (perl command)
$_ default input/output and format matching spaces
$| controls for the current selection Buffer of the output file handle of
$~ the name of the current report format
$` the string before the last format match information
$' the string after the last format match information
$+ the last match of the last regular expression search format A parenthesis
$<real ID of the user currently executing the interpreter
$ contains the result of the parentheses corresponding to the last matching regular expression
$= number of printable lines on the current page
$> effective user ID of the current process contains the filename of the script being executed
$ARGV The current file name when reading from the default file handle
%ENV List of environment variables
%INC List of files included by do or require
%SIG List of signals and their handling
@_ The parameter list passed to the subroutine
@ARGV The command line parameter list passed to the script
@INC The list of directories to be searched when importing the module
$-[0] and $+[0] represent the current matching regular expression being used The starting and ending positions in the matched string

while(){ 
  my($date,$desc,$income,$expend) = unpack(“A10xA27xA7xA*”); 

Simple explanation:

  A10: A means ASCII, A10 means 10 ASCII characters, Date is represented by 10 ASCII codes; x
  : x means null byte is also equal to skip a byte, which means we have to skip a char (|),
  A27: Then follow 27 ASCII chars,
  x: then skip a vhar,
  A7: connect 7 ASCIIs again,
  x: skip a char,
  A*: Finally, A* means that no matter how many chars there are behind, all are included .

During normal subroutine calls, the @ISA array is not searched. But if the user calls the subroutine with the syntax of calling the method, the program will search the @ISA array.

  @ISA = qw(Exporter Net::Cmd IO::Socket::INET);
 
vars is a Perl pragma used to predefine global variables. These predefined global variables in the qw() list can be used in the entire Perl file, and there will be no alarm if use strict is used:
use vars qw($TELNET_IAC $TELNET_IP $TELNET_DM);
($TELNET_IAC,$TELNET_IP, $TELNET_DM) = (255,244,242);


$-[0] and $+[0] represent the start and end positions of the current matching regular expression in the matched string |-
open an "output to" pipe, then you can open it to you This filehandle write count
- | Open a "from" pipe, then you can read data from this filehandle


#!/usr/bin/perl
print $_.”\n”; #Default input.
print @_."\n";#function parameters


#Local variable
print $&."\n";#When the string is used for pattern matching, the string is divided into three parts: the part before the match, the part after the match, and the part after the match. Any part may be empty, this variable refers to the most recent match on the string.
print $'."\n"; #The part after the matching part.
print $`."\n"; #The latest match, the previous part of the match.
print $+."\n"; #The part matched by the subexpression in the last parenthesis.
print $*."\n";#By default, in order to speed up the matching, Perl assumes that the pattern does not include new lines, that is, only performs single-line matching. If you want to perform multi-line matching, set this value to 1.
print @+."\n"; #This array holds the offset of the end of the last successful sub-match of the current match. $+[0] is the offset of the entire match. $+[1] is the offset where $1 ends, and $+[2] is the offset where $2 ends.
print @-."\n";#$-[0] is the offset from the start of the last successful match. $-[n] is the offset of the nth subpattern, or undef if there is no match. $-[0] can also
be regarded as the offset of the start of the entire match. $-[1] is where $1 starts, $-[2] is where $2 starts, and so on.
print
#Input and output variables
print $.."\n"; #The current row number of the latest read operation. Explicitly closing the file handle resets the line count.
print $/."\n"; #Enter the record separator, the default value is a new line.
print $,."\n";#The output field separator of the print operation.
print $\.."\n"; #print operation's output record delimiter. Typically used to omit newlines.
print $"."\n";#When the array is converted into a string, the elements are separated by spaces by default (for example, when printing an array). This variable represents the separator, and the default is spaces. print $^
L ."\n";#The output character when performing a paper feeding action. The default is \f.
print $:."\n";#It is the character set that can be used as a line break at present. The default value is " \ n" (that is, blanks, newline characters, and hyphens).
print $^A."\n"; #The current value of the write collector for the formatted line.


#Error variable
print $?."\n";#$CHILD_ERROR contains the end status of the latest executed external program. These programs are usually executed through pipelines, dots (") or system functions.
print $!."\n";#$OS_ERROR, $ERRNO contains system errors. If used in numerical values, it is the system Error code; if used in a string, it is an error message string.
print $^E."\n";#$EXTENDED_OS_ERROR In some platforms, return an extended error message.
print  $@."\n";# $EVAL_ERROR  Perl syntax error message from the last eval command


#System variable
print $$."\n"; #Pid of the Perl process running the current script.
print $<."\n";#The actual user identifier (uid) of the current process.
print $>."\n";#The effective user identifier of the current process.
print $(."\n"; #The actual group identifier (gid) of the current process.
print $). "\n"; #The effective group identifier of the current process.
print $0."\n";#The file name of the Perl script being executed. This parameter is related to the input during execution
print $[."\n";#The serial number of the first element in the array or the serial number of the first character in the substring. The default is 0.
print $]."\n";#Returns the version number, plus the patch level divided by 1000.
print $M."\n";# The content of $M can be used as an emergency memory pool in case Perl has an out-of-memory error. Using $M requires Perl to do a special compilation.
print $^F."\n";#The largest system file descriptor, usually 2.
print $^I."\n"; #Edit the current value of the extension in place. In-place editing can be disabled using undef.
print $^W."\n"; #The current value of the warning switch, true or false.
print $^T."\n";#The time when the current script starts running. In seconds, since 1970.
print $^O."\n";#The operating system name when compiling Perl itself.
print $^X."\n";#The name of the binary Perl executable file.
print $^D."\n"; #The current value of the debug flag.
print $^P."\n";# Whether to enable debugging.
print $ARGV."\n";#The current file name when reading from < >.


#Others
print @ARGV."\n"; #Command line parameters.
print $ARGV."\n";#The file name of the current file, representing the standard input <STDIN>.
print @INC."\n";#Look for the address table of the Perl script.
print %INC; #The directory of the file name included by do or require.
print $#ARGV array length -1

Guess you like

Origin blog.csdn.net/jh035/article/details/128141608