Getting started with Perl-Application of hash

Source: Internet
Author: User

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 corresponding key value
}

My % hash = (# create a hash and assign values to corresponding key/value pairs
"A" => 1,
"B" => 2,
"C" => 3,
"D" => 4,
"E" => 5,
);

My @ k = keys % hash; # extracts the hash Key List
My @ v = values % hash; # extracts the Hash Value List
My $ COUNT = keys % hash; # extract the logarithm of hash key value
Print "@ k/N". "@ V/N", "Number = $ count/N ";

If (% hash) # true if the hash is not empty
{
Print "OK/N ";
}

My % test;
If (% test)
{
Print "OK for test/N ";
}
Else
{
Print "false for test/N ";
}

While ($ key, $ value) = each % hash)
{
Print "$ key => $ value/N ";
}

# Sorting hash keys
Print "/N ";
Foreach $ key (sort keys % hash) # Sort the keys in the hash and put them in the value scalar one by one.
{
Print "$ key => $ hash {$ key}/N ";
}

# Getting system environment variable values
Print "The path is $ ENV {path}/N"; # obtain the system path address

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.