Example of hash in Perl

来源:互联网 发布:用友易代账软件 编辑:程序博客网 时间:2024/05/29 12:39
#!/usr/bin/perl -wuse strict;use warnings;my %name=("fred"=>"flintstone","barney"=>"rubble", "wilma"=>"flintstone", );my $length=keys %name;# Count the number of hashprint "$length\n";while(my($k,$v)=each%name)# List all the elements of hash{print "$k---->$v\n";}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

原创粉丝点击