http://qs321.pair.com?node_id=11119293


in reply to Re: open input files once
in thread open input files once

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

Replies are listed 'Best First'.
Re^3: open input files once
by rnewsham (Curate) on Jul 14, 2020 at 11:47 UTC

    Oh I agree everyone has their own preferences. My comment was mainly to point out why I changed other things as I was finding their code a little unreadable in my pre-caffine state.