map 的奇妙用法
时间:2008-05-16 来源:yjc0407
=hand1
map other usage
use strict;
use warnings;
sub readconfig{
my ($fileName) = @_;
my @contents;
my %tempHash;
open(FH,$fileName);
chomp (@contents = <FH>);
#print @contents,"\n";
%tempHash = map{join ("_", split /\s+/),$_} @contents;//it is very wizardly,
return \%tempHash;
}
my $fil = shift @ARGV;
my $ret = readconfig($fil);
#print %$ret,"\n";
for(sort keys %$ret){
print $_,"->",$ret->{$_},"\n";
}
=pod @ARGV[0]=1.txt
1.txt
tenpctm us weekly
tpatr us weekly
tenpctm us monthly
=cut
map other usage
use strict;
use warnings;
sub readconfig{
my ($fileName) = @_;
my @contents;
my %tempHash;
open(FH,$fileName);
chomp (@contents = <FH>);
#print @contents,"\n";
%tempHash = map{join ("_", split /\s+/),$_} @contents;//it is very wizardly,
return \%tempHash;
}
my $fil = shift @ARGV;
my $ret = readconfig($fil);
#print %$ret,"\n";
for(sort keys %$ret){
print $_,"->",$ret->{$_},"\n";
}
=pod @ARGV[0]=1.txt
1.txt
tenpctm us weekly
tpatr us weekly
tenpctm us monthly
=cut
相关阅读 更多 +