Perl standard
The calibration is a simple unit of data.
The calibration can be an integer, floating point, character, string, paragraph, or a complete Web page.
The following example demonstrates a simple application of the standard weight:
#!/usr/bin/perl $age = 20; # 整数赋值 $name = "W3CSchool"; # 字符串 $salary = 130.50; # 浮点数 print "Age = $age\n"; print "Name = $name\n"; print "Salary = $salary\n";
The above procedure is performed and the output is:
Age = 20 Name = W3CSchool Salary = 130.5
The digital mark-up
The calibration is usually a number or string, and the following examples demonstrate the use of different types of numeric stynum:
#!/usr/bin/perl $integer = 200; $negative = -300; $floating = 200.340; $bigfloat = -1.2E-23; # 八进制 377 , 十进制为 255 $octal = 0377; # 十六进制 FF, 十进制为 255 $hexa = 0xff; print "integer = $integer\n"; print "negative = $negative\n"; print "floating = $floating\n"; print "bigfloat = $bigfloat\n"; print "octal = $octal\n"; print "hexa = $hexa\n";
The above procedure is performed and the output is:
integer = 200 negative = -300 floating = 200.34 bigfloat = -1.2e-23 octal = 255 hexa = 255
String calibration
The following example demonstrates the use of different types of string curly, noting the difference between single and double quotes:
#!/usr/bin/perl $var = "字符串标量 - W3Cschool教程!"; $quote = '我在单引号内 - $var'; $double = "我在双引号内 - $var"; $escape = "转义字符使用 -\tHello, World!"; print "var = $var\n"; print "quote = $quote\n"; print "double = $double\n"; print "escape = $escape\n";
The above procedure is performed and the output is:
var = 字符串标量 - W3Cschool教程! quote = 我在单引号内 - $var double = 我在双引号内 - 字符串标量 - W3Cschool教程! escape = 转义字符使用 - Hello, World!
The standard operation
The following example demonstrates the simple operation of the calibration:
#!/usr/bin/perl $str = "hello" . "world"; # 字符串连接 $num = 5 + 10; # 两数相加 $mul = 4 * 5; # 两数相乘 $mix = $str . $num; # 连接字符串和数字 print "str = $str\n"; print "num = $num\n"; print "mix = $mix\n";
The above procedure is performed and the output is:
str = helloworld num = 15 mix = helloworld15
A multi-line string
We can use single quotes to output a multi-line string, as follows:
#!/usr/bin/perl $string = ' W3Cschool教程 —— 从W3Cschool开始! '; print "$string\n";
The above procedure is performed and the output is:
W3Cschool教程 —— 从W3Cschool开始!
You can also use the syntax format of "here" document to output multiple lines:
#!/usr/bin/perl print <<EOF; W3Cschool教程 —— 从W3Cschool开始! EOF
The above procedure is performed and the output is:
W3Cschool教程 —— 从W3Cschool开始!
Special characters
Below we will demonstrate the application of special characters in Perl, such as __FILE__, __LINE__, and __PACKAGE__, which represent the file name, line number, and package name of the script currently executing.
These special characters are separate tags and cannot be written in strings, such as:
#!/usr/bin/perl print "文件名 ". __FILE__ . "\n"; print "行号 " . __LINE__ ."\n"; print "包名 " . __PACKAGE__ ."\n"; # 无法解析 print "__FILE__ __LINE__ __PACKAGE__\n";
The above procedure is performed and the output is:
文件名 test.pl 行号 4 包名 main __FILE__ __LINE__ __PACKAGE__
v string
An integer that starts with v, followed by one or more periods, is treated as a string of text.
When you want to declare its numeric values directly for each character, the v-string provides a clearer way to construct such a string than the "{1}{14}, "x12c", "x"fa0"" is not easy to understand, I can look at the following example:
#!/usr/bin/perl $smile = v9786; $foo = v102.111.111; $martin = v77.97.114.116.105.110; print "smile = $smile\n"; print "foo = $foo\n"; print "martin = $martin\n";
The above procedure is performed and the output is:
Wide character in print at test.pl line 7. smile = ☺ foo = foo martin = Martin