1:Substring Truncation
$ Value = substr ($ string, $ offset, $ count );
$ Value = substr ($ string, $ offset );
Substr ($ string, $ offset, $ count) = $ newstring;
Substr ($ string, $ offset, $ count, $ newstring );#Equivalent to the previous statement
Substr ($ string, $ offset)= $ Newtail;
In some casesUnpackMore convenient Functions,AlthoughUnpackIs read-only,But it is more efficient.,You can retrieve multiple substrings at a time.
#First5Bytes,Skip3Bytes,Retrieve again2Items8Bytes,Finally, retrieve the remaining
#(Note::Only supportedASCII,Not SupportedUnicode)
($ Leading, $ S1, $ S2, $ trailing) = unpack ("A5 X3 A8 A *", $ data );
#Per5Split byte into Arrays
@ Fivers = unpack ("A5" X (length ($ string)/5), $ string );
#Split into single-character Arrays
@ Chars= Unpack ("A1" x length ($ string), $ string );
2.Set the Initial Value
#Set$ BAssigned$,If$ BNot true,Then$ CAssigned$
$ A = $ B | $ C;
#When$ XWhen not true,Set$ YAssigned$ X
$ X | = $ Y;
When 0 ," 0 ", And""Is the valid value of the Variable,Variables can be defined in this way.:
#Set$ BAssigned$,If$ BNot Defined,Then$ CAssigned$
$ A = defined ($ B )? $ B: $ C;
#FuturePerlIt supports "new" or defining operators.
$ A = $ B // $ C;
3.No temporary variable exchange value
($ Var1, $ var2) = ($ var2, $ var1 );
In fact, we can exchange more than this.2Variable (s). It is very convenient to directly exchange multiple variables.
4.Conversion of characters and values
$ Num= Ord ($ char );
$ Char = CHR ($ num );
To be continue .......