#!/usr/bin/perl use strict; use warnings; #https://perlmonks.org/?node_id=1230556 #Normal open & process Input file would be # open my $inp, "<", "Inp-file-name"; # while (<$inp>){ # .. process One record , now located in $_ # } # close $inp; my @New_file = ( # This tracks info for each output file {FILENAME=>"File-for-col1.txt", FH=>undef}, {FILENAME=>"File-for-col2.txt", FH=>undef}, ); for my $file(@New_file){ open $file->{FH}, ">", $file->{FILENAME} or die "ERROR: Cannot open $file->{FILENAME}: $!"; } while (<DATA>){ my ($header, @columns) = split ; print "DEBUG: hdr=$header .. got ", scalar (@columns), " columns\n +"; my $col_idx=0; for my $file(@New_file){ print {$file->{FH}} $columns[$col_idx],"\n"; $col_idx++; } } for my $file(@New_file){ close $file->{FH}; } __DATA__ MT-TA 5.36272153463324 21.4508861385329 8.04408230194985 3 +4.857689975116 0 0 0 13.4068038365831 MT-TC 24.1322469058496 160.881646038997 48.2644938116991 3 +7.5390507424327 45.5831330443825 0 0 104.573069925348 MT-TD 10.7254430692665 10.7254430692665 0 2.68136076731662 + 0 176.969810642897 1.34068038365831 445.105887374559
As a computer, I find your faith in technology amusing.
In reply to Re: General Help/Advice Needed
by NetWallah
in thread General Help/Advice Needed
by PandaRaey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |