Bjorn Van Blanckenberg wrote:

>
> #!/usr/bin/perl
>
> use strict;
> use Getopt::Long;
>
> GetOptions(\my %opt, 'filepath=s');
>
> my $filepath = (%opt->{'filepath'});
>
> my @fields = ();
> my @sorted = ();
> my $lastbit = 1;
> my @bits = ();
>
> open(INFILE,$filepath);
>
> chomp(@fields = <INFILE>);
>
> @sorted =
>         map { $_->[0] }
>         sort { $a->[5] cmp $b->[5] }
>         map { [ $_ , (split /\t/) ] } @fields;
>
> foreach (@sorted){
>         @bits = split;
>         print "\n" if ($bits[4] ne $lastbit);
>         print "$_\n";
>         $lastbit=$bits[4];
> }
>
> this is what I have know

Do you mind explaining a little about how the code you have so far accomplishes
its task.  It looks very similar to the example code posted on this thread.  If
I am not mistaken, the code was posted to encourage you to understand how those
operations work

> but al it does is sorting according item 5 but
> want it to look in all the items of column 5 and if it contains item 5
> print it in one block and then the next block separated with an return
> so that

Huh?

> one  title   state   name   testing   number
> two  title2   state2   name2   final   number2
> one  title3   state3   name3   pre   number3
> four  title4   state4   name4   tesing2   number4
> six  title5   state5   name5   testing3   number5
> dip  title6   state6   name6   pre2   number6
> fun  title7   state7   name7   final2   number7
>
> becomes
>
> one  title   state   name   testing   number
> four  title4   state4   name4   tesing2   number4
> six  title5   state5   name5   testing3   number5
>
> two  title2   state2   name2   final   number2
> fun  title7   state7   name7   final2   number7
>
> one  title3   state3   name3   pre   number3
> dip  title6   state6   name6   pre2   number6

I don't quite understand.  In column 5, I see number, number4, , number5, then
back to number2.  Likewise with column 2:  I see state, then state2, then....Oh,
I see [banging forehead with wet rutabaga]  you're using 1-based indexing.  So
you are calling column 0 column 1, etc.  OK.  Please warn us when you do that.

It sounds like you are going to need to do this in two steps, first getting the
groupings, then sorting each grouping in turn.   Unfortunately, I find it almost
impossible to understand cryptic coding style as you use above, but if you can
eplain how the code above is working for you, we can probably help you extend
that process to do the sub-sort on each grouping

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to