in reply to Re^3: divide multi-column input file into sub-files depending on specific column's value
in thread divide multi-column input file into sub-files depending on specific column's value
I was only getting this one warning but I thought it would be ok...? Oops :( I fixed it now.
I'm now facing another problem - I'm trying to print the formatted input into a new file so that I have the nicely formatted input saved somewhere.
However when I do
#!/usr/bin/perl use warnings; use strict; my %fhs; # hash with last_column values open my $INPUT, '<', 'input_file' or die $!; while (my $line = <$INPUT>) { #chomp; # this gives me syntax errors??? my @columns = $line =~ m/\s*(-?[.\d]+)/g; # split columns foreach ($columns[$#columns]) { # foreach element of the last column + = cluster ID open my $FORM, '>', 'output.FORM' or die $!; my $columnform = "%10s"x(@columns) . "\n"; # printf ($FORM $columnform, @columns); # hangs, creates empty file printf $columnform, @columns; # prints on screen correctly close $FORM; } }
When I print on screen, it prints fine. When I try to print in a file, it doesn't. You might notice that I changed the way I split my columns as the fixed width solution was a bit easier to understand but also a bit dangerous as I can't be 100% that all files will have fixed width entries, so I changed it. I'm probably a pain but if you could hint what's happening with printf I'd be super grateful.
Edit: I'm also trying this - where the $FORM printf bit is out of the loop, and interestingly it does print something, but it's only one random line.#!/usr/bin/perl use warnings; use strict; my %fhs; # hash with last_column values open my $INPUT, '<', 'input_file' or die $!; while (my $line = <$INPUT>) { #chomp; # this gives me syntax errors??? my @columns = $line =~ m/\s*(-?[.\d]+)/g; # split columns open my $FORM, '>', 'output.FORM' or die $!; my $columnform = "%10s"x(@columns) . "\n"; # printf ($FORM $columnform, @columns); # hangs, creates empty file printf $columnform, @columns; # prints on screen correctly close $FORM; foreach ($columns[$#columns]) { # foreach element of the last column + = cluster ID # blah } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: divide multi-column input file into sub-files depending on specific column's value
by AnomalousMonk (Archbishop) on Jul 05, 2016 at 16:34 UTC | |
|
Re^5: divide multi-column input file into sub-files depending on specific column's value
by BrowserUk (Patriarch) on Jul 05, 2016 at 16:11 UTC | |
by angela2 (Sexton) on Jul 05, 2016 at 16:23 UTC | |
by Anonymous Monk on Jul 05, 2016 at 16:39 UTC |