SoFunction
Updated on 2025-04-07

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 expressions
Perldoc –f function name
Perldoc module_name View module
Perldoc –v Variable Name View Variable
Perldoc perlop view operator

Check module-related functions:

–d –e 0
module::submod
module::submod

Test program run time:

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

symbol:

<=> Spaceship operator, spaceship operator: three-way comparison number operator. $a<=>$b This operator compares two numbers and returns -1,0,1. Returns 1: $a>$b, returns 0: $a=$b, returns -1: $a<$b.
$a, $b represents the first and second scalars or arrays when used in sort
$! Returns an error number or error string according to the context content
$" list separator
$# The default digital output format when printing numbers
$$ Process ID of Perl interpreter
$% Current page number of the current output channel
$& string matching the previous format
$( group ID of the current process) Valid group ID of the current process
$* Setting 1 means processing multi-line format. Now it is mostly replaced by the /s and /m modifiers.
$, current output field separator
$. The current input line number of the last read file
$/ The current input record separator is the new line by default
$: character setting, after which the string will be separated to fill in consecutive fields.
$; Delimiter used when simulating multidimensional arrays.
$? Returns the status of the previous external command
$@ Error message returned by Perl interpreter from eval statement
$[ Index number of the first element in the array
$\ The delimiter for the current output record
$] The subversion number of the Perl interpreter
$^ The output format name of the top page of the current channel
$^A Variable used to save formatted data before printing
$^D The value of the debug flag
$^E OS extension error message in non-UNIX environments
$^F The maximum file bundling value
$^H Syntax check status activated by the compiler
$^I The value of the built-in control editor
$^L The paper-travelling character sent to the output channel
$^M Size of spare memory pool
$^O Operating system name
$^P Specifies the internal variable of the current debug value
$^R The last evaluation result of the regular expression block
$^S Current interpreter status
$^T Starting from the new century, the steps are calculated in seconds.
$^V perl version
$^W Current value of the warning switch
$^X The name of Perl binary executable code (perl directive)
$_ Default input/output and format matching space
$| Controls buffering of the currently selected output file handle
$~ Name of the current report format
$` string before the previous format match information
$' string after matching information in the previous format
$+ The last bracket that matches the previous regular expression search format
$< The real ID of the user currently executing the interpreter
$ contains the result of brackets corresponding to the previous matching regular expression
$= The number of printable lines on the current page
$> The valid user ID of the current process contains the file name of the executing script
$ARGV The current file name when read from the default file handle
%ENV environment variable list
%INC list of files contained by do or require
%SIG signal list and how to process it
@_ List of parameters passed to subroutine
@ARGV Command line parameter list passed to script
@INC List of directories to search when importing modules
$-[0] and $+[0] represent the starting and ending positions of the currently matched regular expression in the string being matched

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

Simple explanation:

A10: A represents ASCII, A10 represents 10 ASCII characters, and Date represents 10 ASCII codes;
x  : x means null byte is also equal to skip a byte, which means we want to skip a char (|),
A27: Then 27 ASCII chars,
x  : Then skip a vhar,
A7: Connect 7 more ASCIIs,
x  : Skip a char,
A*: Finally, A* means that no matter how many chars there are, they are all included.

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

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


$-[0] and $+[0] represent the starting and ending positions of the currently matched regular expression in the string being matched
|- Open an "output to" pipeline, then you can write a number to the file handle you opened
-| Open a "from" pipeline, then you can read data from this file handle


#!/usr/bin/perl
print $_."\n";#Default input.
print @_."\n";#Function Parameters


#Local Variables
print $&."\n";#When a string is used for pattern matching, the string is divided into three parts: match the previous part, match the part on it, and match the later part. Any part may be empty, and this variable refers to the string on the last match.
print $'."\n";# matches the part after the part.
print $`."\n";#Latest match, match the previous part.
print $+."\n";#The part where the subexpression in the last parentheses matches.
print $*."\n";# By default, in order to speed up the matching speed, Perl assumes that the pattern does not include new rows, that is, only single row matching is performed. If you want to perform multiple row matching, set this value to 1.
print @+."\n";# This array holds the offset at the end of the last successful submatch of the current match. $+[0] is the offset of the entire match. $+[1] is the offset ending of $1, and $+[2] is the offset ending of $2.
print @-."\n";#$-[0] is the offset at the beginning of the last successful match. $-[n] is the offset of the nth subpattern, or undef, if there is no match. $-[0] is also OK
It is regarded as the offset at the beginning 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 number of rows that were last read. Explicitly close the file handle and reset the number of lines.
print $/."\n";# Enter the record separator, the default value is a new line.
print $,."\n";#print operation output domain separator.
print $\.."\n";#print The output record separator for the operation. Usually used to omit newlines.
print $"."\n";# When an array is converted to a string, elements are separated by spaces by default (for example, when printing an array). This variable represents this separator, and the default is spaces.
print $^L."\n";# Characters output when performing a paper feed action. The default is \f.
print $:."\n";# is a collection of characters that can currently be used as a fold line. The default value is "\n" (i.e., blank, line break, and hyphen).
print $^A."\n";# Format the current value of the write collector of the row.


#Error variable
print $?."\n";#$CHILD_ERROR contains the latest execution of the external program end state. These programs are executed through pipelines, anti-dot (") or system functions.
print $!."\n";#$OS_ERROR, $ERRNO contains system errors. If used in a numerical value, it is the system error code; if used in a string, it is the error message string.
print $^E."\n";#$EXTENDED_OS_ERROR On some platforms, return extended error message.
print $@.”\n”;#$EVAL_ERRORPerl syntax error message from the previous eval command


#System Variables
print $$."\n";#The pid of the Perl process that runs the current script.
print $<."\n";#The actual user identifier (uid) of the current process.
print $>."\n";#Valid user identifier for the current process.
print $(."\n";#The actual group identifier (gid) of the current process.
print $)."\n";#Valid group identifier for 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 sequence number of the first element in the array or the sequence 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";#$M content can be used as an emergency memory pool for use when Perl issues an out-of-memory error. Use $M to require Perl for special compilation.
print $^F."\n"#The largest system file descriptor, usually 2.
print $^I."\n";# Edit the current value of the extension in place. You can use undef to prohibit editing in situ.
print $^W."\n";#The current value of the warning switch, true or false.
print $^T."\n";#Time when the current script starts running. In seconds, starting in 1970.
print $^O."\n";#The operating system name when compiling Perl itself.
print $^X."\n";#Binary Perl The name of the execution file.
print $^D."\n";#The current value of the debug flag.
print $^P."\n";# Whether to turn on debugging.
print $ARGV."\n";# The current file name when read from < >.


#other
print @ARGV."\n";# command line arguments.
print $ARGV."\n";#The file name of the current file represents the standard input <STDIN>.
print @INC."\n";# Find the address table of Perl scripts.
print %INC;#Directory of file names contained by do or require.
print $#ARGV array length-1