Variable Hashes (Associated Array), which means we can set the keys. (Or values in children, France is a message) to the Array by using the following format.
The announced value variables Array (announced in the variable value to A Ray Hashes symbol % is used) such as.
%day_in_month = ( "January" => 31, "Febuary" => 29, "March" => 31);
%number_hashes = ( "01" => "Monday", "02 '=>" Tuesday "," 03 "=>" Wednesday ");
To access the value of a variable Array Hashes this form below.
print $day_in_month ( "January"); # 31 display.
print $number_hashes ( "01"); # display Monday.
Change the value of Array key need. Look like.
$day_in_month ( "Febuary") = 28; # %day_in_month = ( "January" => 31, "Febuary" => 28, "March" => 31);
To count all members of A-ray. (Array variables using the same simple).
print $#day_in_month; # value is 3.
To see all of Array key variables.
print key %day_in_month; # display January, Febuary, March.
@keys_day = keys %day_in_month; # keys can also collect an Array of Hashes in the Array variables with a simple consequence @keys_day = ( "January", "Febuary", "March").
ถ้าต้องการเรียกดูค่าทั้งหมดของตัวแปร Array แบบ Hashes
print values %day_in_month; # display 31, 28, 31.
Hash in Perl.
Array in Perl.
Array variable that refers to a simple variable array, which costs around other children in France it will be a number starting from 0, 1, 2, ... to becoming the variables in the Perl language A simple array. This model is used as follows.
The announced value variables Array (announced in the variable value to array Standard. Using the @symbol) such as.
@number_practice = (1, 2, 3, 4, 5);
@string_practice = ( "default", "with", "language", "Perl");
To access this Array variables are used as models.
print $number_practice[3]; # program will display 4.
print $string_practice[3]; # program to display Perl.
Changes in values in the children Array Alliance needed. Use the form below.
$number_practice[3] = 10; # therefore variable. @number_practice = (1, 2, 3, 10, 5).
$string_practice[3] = "C"; # therefore variable. @string_practice = ( "start," with "," language "," C ").
To determine the number of members of the Array using the following form.
print $#number_practice; # 5 displayed.
The need to reduce the number of members of the Array using the following form.
$#number_practice = 3; # means that the lower member of the array to the remaining 3.
To view all the values of variables a simple Array.
print @number_practice; # Display 1 2 3 10 5.
print @string_practice; # display default language to C.
Scalar variable in Perl.
Scalar variables are common variables that can be either numeric character string, such as time.
$ a = "8"; # $ a variable is a string value "8".
$ b = 5; # variable $ b is a numeric value 5.
$ c = $ a 5; # remove string variables. (Plus symbol) to figure it will be immediately converted to numbers. Therefore, in this case would have cost $ c variable is 13.
$ d = $ a. "1"; # remove string variables. (symbol dot) with any number or string. Up to a string value. Therefore, in this case, the variable $ d to have a "81".
Using "until" and "do..until" for looping.
- "until" is looping statement for condition is false. Value opposite while.
$a = 0;
until ($a <0) (
print $ a. ",";
$a--;
)
# 0 will be displayed, because when set to $a = 0 then the check is if the conditions $a <0 to undo the block command. So if $a = 0 is a blog command until the display value from the variable $a after that $a will be reduced up to 1 value, so $a = -1 and the Blue of the year to check conditions again. Will be real terms. When conditions are true. Is the cross-block command in a command Lou year to another.
- do ... until the check until the conditions are similar to the instructions on the blog when conditions are false. And it will work like the do ... while in the first round to take command in a do ... until then check conditions before.
$ a = -1;
do (.
print $ a. ",";
$ a -;
) Until ($ a <0);
# Values are expressed -1, 0.
Using "while" and "do..while" statement.
- "while" is statement for looping same "for" statment. It has format follow.
$a = 0;
while ($a <3) (
$a;
print $a. ",";
)
# Values are shown 1, 2, 3 due to 0 $ a start when loop while on the condition that if $ a is less than 3 in order to make the blog. Over conditions. Will provide variable $ a (Added 1 value) Therefore, when this variable $ a = 1 then display output. Then to check the conditions while until conditions are false.
- do ... while a function like while (condition) () command, but do .. while the first block in order to do do .. while before gradually to check conditions into account, such as when finishing.
$a = 3;
do (
print $ a. ",";
$a--;
) While ($a <3);
# When viewing the variable $ a is 3 and will be valuable in terms of checks in order while the check that if $ a <3 to do in order blog. But in this case, a command do ... while when set to variable $ a = 3 will be made on the blog do ... while the command immediately without prior conditions examined. When a command in the block and then erase the value $ a to a variable cost, so now at $ a = 2, then in order to check conditions while on the set. But in this case, the year of the endless Blue (overflow) to describe, but easy to understand. This command has raised the issue.
Using for statement
- for (;;;) are used as models. (If the language used through PHP, C or some other language, the language may be familiar with this syntax).
for ($i = 1; $i <10; $i++) (
)
# $i mean set to start as 1 and checks that $i is not less than 10 or if less than 10, follow the instructions on the blog. When instructions complete in block (in each round) is the variable $i++ (the plus to add 1) and then check the conditions.
- using "for" statement for display value of all member in array.
for $value (@array) (
print $value;
)
- Displaying keys in member of array.
for $i (keys %array) (
print $i;
)
# For displaying value of all member in array by using keys reference.
for $i (keys %array) (
print $array ($i);
)
Using If and unless statement
Sentence review the terms of the Perl language instructions check the following conditions.
- If that distinction is out.
- Command if ().
if ($ number == 1) (.
).
if ($ string eq "welcome") (.
).
- Command if () else ().
if ($ number == 1) (.
) Else (.
).
- Command if () elsif ().
if ($ number == 1) (.
) Elsif ($ number == 2) (.
).
- Command if () elsif () else ().
if ($ number == 1) (.
) Elsif ($ number == 2) (.
) Else (.
).
- Unless the audit condition is another concern. Used in the opposite if (or other words meaning equal concern else).
unless ($ number == 1) (.
).
# This means that if the variable $ number is not equal to 1.