name here is replaced by 'reference' {$ table {$ country. Symbol @ tells Perl to get the entire array. After the city list is obtained, we sort the city names and print them out.
Line 2-7 is responsible for creating the data structure as follows:
2 while (3 chomp;4 my ($ City, $ country) = Split /,/;5 $ table {$ country} = [] Unless exists $ table {$ country };6 push @ {$ table {$ country}, $ city;7}Obtain the name of the city and country from lines
Copy codeThe Code is as follows:APR_DECLARE_NONSTD (unsigned int) apr_hashfunc_default (const char * char_key,Apr_ssize_t * klen){Unsigned int hash = 0;Const unsigned char * key = (const unsigned char *) char_key;Const unsigned char * p;Apr_ssize_t I;/** This is the popular 'times 33' hash algorithm which is used* Perl and also appears in Berkeley DB. This is one
}[email protected]{reverse (@keys)}#注意 @ cannot be changed to $, because the key requirement in $hash{} is a simple variable, so the parentheses are a numberAnd now I want to circle an array, so it's going to be @, the parentheses are @should correspond to each other.If you enter $hash {@keys} because the key in the $hash curly brace is a simple variable this equ
Copy Code code as follows:
APR_DECLARE_NONSTD (unsigned int) apr_hashfunc_default (const char *char_key,
apr_ssize_t *klen)
{
unsigned int hash = 0;
Const unsigned char *key = (const unsigned char *) Char_key;
const unsigned char *p;
apr_ssize_t i;
/*
* This is the popular ' Times ' hash algorithm which be used by
* Perl and also appears in Berkel
One, what is Perl Hash
A hash is a data structure, and a similar array, that can be stored in or retrieved from a value. However, unlike arrays, the index is not a number, but a name. That is, the index (here, we call it key) is not a number but an arbitrary unique string.
The key can be any string, you can use any string as the key, but they are unique.Another
I. Hash Variables
A hash variable is also called an associated array. Like an ordinary array, you can use a subscript to access the data elements. The difference is that the subscript of a hash variable can not only be a non-negative integer, it can also be other types of simple variables or variable values, that is, the subscript index of the
This article focuses on the concept of a Perl hash table. The Perl language and other programming languages have different features. Here we will share with you the concept of a Perl hash table, in fact, a Perl
This article is focused on the Perl hash table concept, Perl and other programming languages have their own characteristics, here and you share the concept of Perl hash table, in fact, Perl ha
Perl Learning 5 Hash, perllearninghash
[This article is original. Do not reprint it without permission]
Hash is a data structure. It is similar to an array in that it can accommodate any number of values and can be used as needed. The difference between hash and array lies in the indexing method, arrays are indexed by
I am sorry to send a personal advertisement here. If you are interested, you can view it:Http://www.wachnew.com
#! /Usr/bin/perl-W
$ Family_name {"Fred"} = "flinkstone"; # assign a value to the hash key$ Family_name {"Barney"} = "rubble ";
Foreach my $ person (QW/Fred Barney/) # Write the private variable declaration to foreach{Print "the $ person is: $ family_name {$ person}/N"; # output key and correspon
Basic usage # initialize % H as an empty array % H ={}; # use an array to initialize % H as a => 1, B => 2% H = ('A', 1, 'B', 2); % H = ('A' => 1, 'B' => 2); # If the key is a string, % H = (a => 1, B => 2) can be omitted. # Use {} to access print "$ H {A} n "; # Print $ H {B} = '2b '; print "$ H {B} n"; # print 2B # delete key using delete $ H {B }; # Delete 'B' from $ h to clear Perl hash UNDEF % H; obtai
The previous article lists the similarities and differences between the ways of objects and JS in Perl. This continues to complement the array, the hash of the associated operation.
One, array
You can add additions and deletions to the array. Unlike JS is that these functions are global, JS is hanging on the array.prototype.
1, the operation of the tail of the array POPs (delete the last element), push (
Basic usage
#初始化%h is an empty array%h={};#用数组初始化%h for A=>1,b=>2%h= (' A ', 1, ' B ', 2);#意义同上 is just another, more figurative way of writing. %h= (' A ' =>1, ' B ' =>2);#如果key是字符串, you can omit the quotation marks. The following line is the same as the line above%h= (A=>1,B=>2);#用 {} To access print "$h {a}\n";#打印 $h {b}= ' 2b '; Print "$h {b}\n"; #打印2b#删除key用delete Delete$h{b}; #从 $h Delete ' B '
Empty Perl HashUndef%h;
Get all the key values o
APR_DECLARE_NONSTD (unsigned int) apr_hashfunc_default (const char * char_key,
apr_ssize_t * klen)
{
unsigned int hash = 0;
const unsigned char * key = (const unsigned char *) char_key;
const unsigned char * p;
apr_ssize_t i;
/ *
* This is the popular `times 33 'hash algorithm which is used by
* perl and also appears in B
Copy codeThe Code is as follows :#! /Bin/perl
Use strict;
Use warnings;
My % movies;My $ film;My % reverse_result;My $ director;My @ data;
% Movies =('The shining' => 'kubrick ','Ten Commandments '=> 'demille ','Goonies '=> 'spielberg ',);
# Output the hash value. The output result is Kubrick.Print $ movies {'the shining '};
# Simultaneously output keys and valuesForeach $ film (keys % movies){Print "$ fil
Copy Code code as follows:
#!/bin/perl
Use strict;
Use warnings;
My%movies;
My $film;
My%reverse_result;
My $director;
My @data;
%movies =
(
' The Shining ' => ' Kubrick ',
' Ten Commandments ' => ' DeMille ',
' Goonies ' => ' Spielberg ',
);
#输出哈希的值, the result of the output is Kubrick
Print $movies {' The Shining '};
#同时输出键和值
foreach $film (keys%movies)
{
Print "$film is directed by $movies {$film}.\n";
}
#添加空格
p
A description of the variable
A variable is a data item whose value can change as the program runs.
A variable can be anywhere in the program, and you do not need to declare it as a type of feature, as in a high-level language.
The value of a variable can be a string, a number, or a combination of them.
Second, the type of Perl variable
A. Scalar type
$ variable = value;
B. A
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.