in reply to Arrays and regular expressions

Here's how I would do it, assuming that the 'pos' value in the first line is the key:
use strict; my %hash; my $entry; my $line; my $key; open(INFILE, "data") || die; while ($line = <INFILE>) { chomp($line); if ($line) { # in an entry if (!$entry) { # this is the first line $entry .= $line . "\n"; ($key = $line) =~ s/\D//g; } else { $entry .= $line . "\n"; } } else { # left the entry $hash{$key} = $entry; $entry = ""; } } close(INFILE); open(OUTFILE, ">datax") || die; foreach $key (sort(keys(%hash))) { print OUTFILE $hash{$key} . "\n"; } close(OUTFILE);
Hope this helps...

-Ton

-----

Be bloody, bold, and resolute; laugh to scorn
The power of man...

Replies are listed 'Best First'.
Re: Re: Arrays and regular expressions
by mel1rose (Initiate) on Apr 13, 2001 at 00:57 UTC
    Thanks everyone! It's working now! ::mel1rose::