<$in>;
while (<$in>) {
chomp;
print $out join ("\t", (split /\t/)[1,3]), "\n";
}
True laziness is hard work
| [reply] [d/l] |
When there are few fields, I usually prefer to avoid slicing and be more direct:
my (undef, $name, undef, $size) = split /\t/;
or even the full stuff my ($id, $name, $effects, $size) = split /\t/;
I find it a bit more readable but... it's a matter of taste!
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
Io ho capito... ma tu che hai detto?
| [reply] [d/l] [select] |
I find it a bit more readable but... it's a matter of taste!
Don't declare "my" variables that you do not use.
Use a regex when you want to "keep" something.
Use split when you want to "throw away something"
Use list slice to "throw away" extraneous stuff from a split() or a match "global".
my ($id, $name, $effects, $size) = split /\t/; #wrong
Forget even declaring, for example, $effects if it is not used.
Focus the code on what is used from the input - forget the stuff that is not used.
Explain what $effects would have meant - but its not important to this code - in some kind of comment section - if that this important to the overall description of the input file.
The use of "undef" instead of list slice is just fine for a case like this. List slice is great when you want #12, #3, #1, #50-67 in that order. | [reply] [d/l] |