Whitespace to make things easier to read is *completely* within the eyes of the beholder. Most often, I find *removing* extraneous redundant annoying empty lines improving the readability and maintainability. Also cleaning up is only useful if it matches the style of the surrounding project/script/module(s) after the cleanup. e.g. your cleaned-up code would not fit my standards and my code would not fit yours..
And if you clean up, why not go further?
foreach my $key (grep { !m/\t0$/ } keys %data) {
my ($chr, $fivep, $threep, $strand) = split m/\t/ => $key;
say join "\t" => $chr, $fivep, $threep, "-",
map { $data{$key}{$_} // 0 } @files;
}
Less lines more to the point, no need for empty space as each line is clear on itself.
Personally, I'd use Text::CSV_XS with sep => "\t" like this:
use Text::CSV_XS qw( csv );
my @key = qw( chr fivep threep strand );
my @files = qw( file1.tab file2.tab );
my %c7;
foreach my $file (@files) {
csv (in => $file,
out => undef,
sep => "\t",
strict => 1,
on_in => sub { $c7{join ":" => @{$_[1]}[0..3]}{$file} = $_[1
+][6] }
);
}
say join "\t" => @key, @files;
foreach my $key (sort keys %c7) {
say join "\t" => (split m/:/ => $key), map { $c7{$key}{$_} // 0 }
+@files;
}
Enjoy, Have FUN! H.Merijn
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.