perl基础-7 (Perl编程24学时教程)

#!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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值