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
}
}
|