標(biāo)題: hash一段代碼沒看懂,高手解釋下 [打印本頁] 作者: cocoa1227 時間: 2012-05-18 09:53 標(biāo)題: hash一段代碼沒看懂,高手解釋下 #!/usr/bin/perl -w
use strict;
my %hash;
open my $fd,"aa.txt" or die $!;
while(<$fd>) {
$hash{$_} ++; # 這句話怎么理解?
}
close $fd;
open $fd,"bb.txt" or die $!;
while(<$fd>) {
print if $hash{$_} ;
}
close $fd; 作者: zhlong8 時間: 2012-05-18 10:06
和 $i++ 沒什么區(qū)別啊,就是 $hash{$_} += 1; $hash{$_} = $hash{$_} + 1;
open my $fd,"a" or die $!;
while(<$fd>) {
print "file a",chomp($_),"\t";
$hash{$_} ++; # 這句話怎么理解?
print "keys " ,sort(keys %hash),"\t";
print "values " ,sort(values %hash),"\n";
}
close $fd;
=cut;
open $fd,"b" or die $!;
while(<$fd>) {
print if $hash{$_} ;
}
close $fd;
=cut
f:>more a
a
b
c
f:>perl b.pl
file a 1 keys a values 1
file a 1 keys b values 11
file a 1 keys c values 111