Example of hash in Perl
发布时间:2020-12-16 00:08:30 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl -wuse strict;use warnings;my %name=("fred"="flintstone","barney"="rubble","wilma"="flintstone",);my $length=keys %name;# Count the number of hashprint "$lengthn";while(my($k,$v)=each%name)# List all the elements of hash{pr
#!/usr/bin/perl -w
use strict;
use warnings;
my %name=("fred"=>"flintstone","barney"=>"rubble","wilma"=>"flintstone",);
my $length=keys %name;# Count the number of hash
print "$lengthn";
while(my($k,$v)=each%name)# List all the elements of hash
{
print "$k---->$vn";
}
my $given_name=<STDIN>;# The Usage of <STDIN>
chomp $given_name;# Delete the "n"
print "$name{$given_name}n";
output: 3 barney---->rubble wilma---->flintstone fred---->flintstone fred flintstone (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |