In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you what Perl basic knowledge points, I believe most people do not know how, so share this article for everyone's reference, I hope you have a lot of gains after reading this article, let's go to understand it together!
Perl basics
(1)helloworld.pl
usestrict;//turn on strict syntax and variable checking
usewarnings;//turn on additional compile and runtime warnings
print"helloworld\n";//Print information
Run mode, command line: perlhelloworld.pl
(2) Perl Basic Variables and Simple Expressions
There's only one variable, a string.
Definition of variables:
my$size=42;#This is a comment
My stands for local variable, 42 is actually "42"
If the variable is not initialized, it is assigned a special value undef, and comparing, printing, or performing arithmetic operations on undef will cause errors.
(3) Perl base print variables:
print"size=$size"
print size=42;
If you want to print "$," escape is required
perl also has printf, similar to c, but only used where precise control of variable format is required, such as: printf"%3d:%-20s%5.2f\n",$sequence,$description,$amount;
(4) Perl basic operators
As with C, there are:
.:string concatenation
**: Power
x: Repeat, for example: my$no="no"x3;
(5) Reference rules for Perl basics
If there are characters after the output string, they need to be separated by braces, for example:
my$title="$name\t${size}inches"
If you don't want Perl to tamper with your string, use single quotes. Perl doesn't interpret anything in single quotes unless\'and\\
(6) Perl fundamental numerical constants
Same as c, including octal and hexadecimal, underscore is also allowed in numbers, for example:
my$cost=1_333_832;
(7) Perl basic read input
Read inputs from standard inputs:
$variable=;(stdin can also be all lowercase)
The entire line will be read up to the new line, including your carriage return.
chomp($name), which removes the new line at the end of the string
(8) If statements and relational operators
For example:
if($size==1){
}elsif($size==2){//Note not elseif
}else{
die("Error");//Print error message and exit
}
Relational operators are used for numbers and strings, respectively:
numeric string
==eq
!= ne
=ge
If the string is operated on by a numeric relationship, the string is converted to 0 and a warning is displayed
(9) Whether the test variable has a value
defined($value)
Def ($value)
(10) True definition
false: undefined variable, empty string, value "0"
true: Other circumstances
(11) Perl Basic Loop Statements
while(condition){
last;//exit loop, similar to break in c
}
for($i=0;$i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.