in reply to Arrays and regular expressions
Hope this helps...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);
-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 |