Ok, here's some quick and dirty code... not very functional under 'strict'
like this, but it would get the job done:
### open the input file ###
open I, "1.txt";
### read it all into $in ###
{ local $/; $in = }
### split $in on a newline and for as long as that goes, execute all in the
for loo
Ok, here's some quick and dirty code... not very functional under 'strict'
like this, but it would get the job done:
### open the input file ###
open I, "1.txt";
### read it all into $in ###
{ local $/; $in = }
### split $in on a newline and for as long as that goes, execute all in the
for loo
On Jun 8, Pedro A Reche Gallardo said:
>Hi all, I have a file with 20 columns of positive and negative decimal
>numbers (eg: 9.782 -8.983) separated by a black space, and everycolumn
>is marked on top with an single alphabet letter.
>A D C B
>9.782 -8.983 -3.483 -3.219
>0.995 -0
Sorry to reply to my own post, but I just looked carefully at Ondrej's solution,
and the nice thing about it is that it doesn't matter what order the columns are
in, it will always sort on the header. So his program is a lot more generic than
mine. Nice!
Pete
Pete Emerson wrote:
> Here's my
Pedro A Reche Gallardo wrote:
: Hi all, I have a file with 20 columns of positive and negative decimal
: numbers (eg: 9.782 -8.983) separated by a black space, and everycolumn
: is marked on top with an single alphabet letter.
: This is an example.
:
: A D C B
: 9.782 -8.983 -3.
Here's my version. It's pretty straightforward, but maybe Ondrej's solution is
far better for some reason?
#!/usr/bin/perl -w
use strict;
my $inputfile; my $outputfile;
$inputfile='myinfile.txt';
$outputfile='myoutfile.txt';
open (INFILE, "$inputfile") || die "Can't open input file\n";
open (OU
#!/usr/bin/perl -w
use strict;
## get first line with col names
my $headers = <>;
## store column names into array
my @column_names = split /\s+/, $headers;
## print out first line (sorted column names)
print join(' ', sort @column_names), "\n";
## The hash %column_order will contain column na