On Sun Feb 15 2009 @  9:48, Jack Butchie wrote:
> I used a tab, then a pipe, both produced the same results.
>
> LAWNS|123|GOOD
>
> LAWNS|12|GOOD

The results are the same because the test is for the whole line. If you
only want to test one field, you need a different script. For example, this
will test the first field (only) of each line:

    #!/usr/bin/perl -w

    my $file = shift @ARGV;

    open IN, $file or die "Couldn't open $file: $!";
    my $before;

    while (my $line = <IN>) {
      my $now = (split /\|/, $line)[0];
      if ($before and $before ne $now) {
        print "\n";
      }
      print $line;
      $before = $now;
    }

    close IN;

On the other hand, this is getting more and more hacked together, as you
can see. The big problem remains that you are going to have a script that
you can't maintain because you don't know how it works.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to