#!usr/bin/perl -w
#hash
%hash1=("aaaa"=>1,"bbbb"=>2,"cccc"=>3,"dddd"=>4);
foreach $key(sort keys %hash1)
{
print $key;
print $hash1{$key};
print "\n";
}
%hash2 = %hash1;
print %hash2;
print "\n";
print keys %hash2;
print "\n";
print values %hash2;
print "\n";
print reverse %hash2;
print "\n";
print $hash2{aaaa};
print "\n";
print "sort", "\n";
@arraykeys = values %hash2;
for $k (@arraykeys)
{
print $k;
}
print "sort1", "\n";
foreach (sort {$b<=>$a} @arraykeys) #{$b<=>$a} 数字排序
{
print "$_";
}
print "sort2", "\n";
foreach (sort {$a<=>$b} @arraykeys)
{
print "$_";
}
#########################################
print "\n", "local,my our" ,"\n";
sub changenumber
{
$foo = 100;
}
sub main
{
my $foo = 0;
&changenumber;
print '$foo=', $foo;
}
&main;
perl基础-7 (Perl编程24学时教程)
最新推荐文章于 2020-12-19 12:48:20 发布