What are the basic operators of Perl
This article mainly shows you "What are the basic Perl operators?" The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn "What are the basic Perl operators?" This article.
numeric operator
+、-、*、/、%、**、++、--、+=、-=、*=、/=
..、.、x、,
@a = (1 .. 4); # @a = (1,2,3,4), note: cannot be from large to small
$s = "Test". 1; # $s = "Test1"
$s .= 2; #$s = "Test12"
@a = (1) x 4; # @a = (1,1,1,1)
$s = "A" x 4; # $s = "AAAA"
my ($a,$b) = (1,2); # my $a = 1; my $b =2;
$a=$b+1,$b=$a+1; # $a=$b+1;$b=$a+1;
($a,$b) = (1,2);
($a,$b) = ($b+1,$a+1); # $a=3, $b=2
#is not equal to: $a=$b+1; $b=$a+1;
logical operators
Logical OR: $a|| $b or $a or $b #either a or b is true
logical AND: $a && $b or $a and $b #true only if both a and b are true
Logic is NOT: ! $a or not $a #a is true when false
Logical XOR: $a xor $b # a, b is true when one is true and one is false
Conditional operators (ternary operators):
Conditions? Value1: Value2. When the condition is true, the value is 1, and when it is false, the value is 2, such as:
$result = ($var == 0) ? 14 : 7;
That's all for "What are the basic Perl operators?" Thanks for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!