Hash in Perl.

วันจันทร์ที่ 14 กันยายน พ.ศ. 2552

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.

0 ความคิดเห็น:

แสดงความคิดเห็น

 
 
 
 
Copyright © Basic Perl