Bjorn Van Blanckenberg wrote:
> 
> On 28-feb-04, at 20:32, R. Joseph Newton wrote:
> 
> > Bjorn Van Blanckenberg wrote:
> >
> >> let say that the file contains these items (every item is seperated
> >> with a tab)
> >>
> >> one  title3   state3   name3   pre   number3
> >> dip  title6   state6   name6   pre2   number6
> >
> > So what changes have you made in the code to reflect this diffeence in
> > specification.  Let us know how *your* adaptations work.
> 
> #!/usr/bin/perl
> 
> use strict;
> use Getopt::Long;
> 
> GetOptions(\my %opt, 'filepath=s');
> 
> my $filepath = (%opt->{'filepath'});

That is not how you access a hash value.  There is nothing to
dereference as %opt is a hash, not a reference to a hash and a hash
value is a scalar so it should start with '$' not '%'.

my $filepath = $opt{filepath};


> my @fields = ();
> my @sorted = ();
> my $lastbit = 1;
> my @bits = ();

For the array declarations the ' = ()' is redundant as my() creates
arrays with that value by default.


> open(INFILE,$filepath);

You should *ALWAYS* verify that the file was opened successfully.

open INFILE, $opt{filepath} or die "Cannot open $opt{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);

Your problem is that all the values in $bits[4] are different so that
will always print a newline.

>         print "$_\n";
>         $lastbit=$bits[4];
> }


John
-- 
use Perl;
program
fulfillment

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