in reply to Re: Any hints on how to do this?
in thread Any hints on how to do this?

Hi CountZero, thanks for your time... That was exactly what I was thinking of doing, but I don't seem to be getting anywhere.. Do I need an array or just check the name in the following line, perhaps using the <> to move to the following line and do my pattern matching again?

Replies are listed 'Best First'.
Re^3: Any hints on how to do this?
by CountZero (Bishop) on Jul 25, 2006 at 21:59 UTC
    No need to use an array:
    use strict; my ($saved_name, $number) = split /\s/, <DATA>; print "$saved_name\t$number\n"; while (<DATA>) { (my $name, $number) = split /\s+/, $_; if ($saved_name eq $name) { print ' '; } else { print $name; } print "\t$number\n"; $saved_name=$name; } __DATA__ GEORGE 21 GEORGE 45 NICK 12 PETER 27 JIM 18 JIM 87 CHRIS 33
    Output:
    GEORGE 21 45 NICK 12 PETER 27 JIM 18 87 CHRIS 33

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law