Bryan R Harris wrote:
>
> > Bryan R Harris wrote:
> > >
> > > I suppose it does look a little bizarre. Actually, my goal is a little
> > > more complex. We have a simulation that outputs data files, but often up
> > > to 90% of the data is redundant. So I'm trying to write a filter for the
> > > data. I have to:
> > >
> > > 1. open and load the file
> > > 2. strip all comments (marked with a #) and blank lines off the top
> > > 3. sort by column 4, then by column 3
> > > 4. remove all lines at the top that have a 0 in column 5
> > > 5. write the comments + sorted lines back out to a new file
> > >
> > > Unfortunately I'm new enough at perl that I've only got steps 1 and 2 to
> > > work so far... I got some great help here on the list for step 3, though
> > > the code at
> >
> > (URL for analysis of Schwartzian Transform by tchrist)
> >
> > > seems much more concise. I just haven't gotten it to work on my array
> > > instead of a string.
> >
> > How are your columns defined? Fixed width? Space separated?
>
> I have to sort before I remove the lines at the top because the lines that
> have the zeros in column 5 are not at the top. The whole point of the task
> is not to sort the data, but to filter unneeded data. Some zeroes in
> column 5 are okay, but the redundant ones are the ones at the top after
> sorting by col 4 then by col 3.
>
> The columns are tab delimited, then the entries are right justified using
> spaces.
This should get you started:
# Step 1
open FILE, 'filename' or die "Cannot open filename: $!";
# Step 2
my @lines = grep { !/#[^#]*$/ and /\S/ } <FILE>;
# Step 3 - assumes columns 3 and 4 contain numeric data
my @sorted = map { $_->[2] }
sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] }
map { [ (split /\t/)[3,2], $_ ] }
@lines;
# Step 4
shift @sorted while (split /\t/, $sorted[0])[4] =~ /0/;
# Step 5
# you're on your own :-)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]