- 论坛徽章:
- 7
|
回复 9# 不仅仅是符号
while ($line=<INN>) {
chomp $line;
@colu=split(/\t/,$line);
$key=$colu[0]."\t".$colu[1]."\t".$colu[2]."\t".$colu[3]."\t".$colu[4];
$hash{$key}=1;
}
0: use perltidy [ perltidy -b abc.pl ]
- my %hash;
- while ( my $line = <INN> ) {
- chomp $line;
- my @colu = split( /\t/, $line );
- my $key =
- $colu[0] . "\t"
- . $colu[1] . "\t"
- . $colu[2] . "\t"
- . $colu[3] . "\t"
- . $colu[4];
- $hash{$key} = 1;
- }
复制代码 1: use join
- my %hash;
- while ( my $line = <INN> ) {
- chomp $line;
- my @colu = split /\t/, $line;
- my $key = join "\t", @colu;
- $hash{$key} = 1;
- }
复制代码 2: no chomp;
- my %hash;
- while (<INN>) {
- my @colu = split;
- my $key = join "\t", @colu;
- $hash{$key} = 1;
- }
复制代码 3: no tmp array
- my %hash;
- while (<INN>) {
- my $key = join "\t", split;
- $hash{$key} = 1;
- }
复制代码 4: split /\t/ + join "\t" ==> do NOTHING!!
- my %hash;
- while (<INN>) {
- chomp;
- $hash{$_} = 1;
- }
复制代码 5: no chomp; this scenario BUUUUUU xuyao chomp
- my %hash;
- while (<INN>) {
- $hash{$_} = 1;
- }
复制代码 6: use map
- my %hash = map { $_, 1 } <INN>;
- my %hash = map { chomp; $_, 1 } <INN>; # if chomp
- my %hash = map { $_, chomp } <INN>; # if chomp
复制代码 |
|