On May 13, Thomas Leuxner said:
>#mydomain.com
>mydomain.com anything
>[EMAIL PROTECTED] tlx
>....
>#newdomain.com
>newdomain.com anything
><addresses ...>
>
>#somewhere.com
>somewhere.com anything
><addresses ...>
I suggest you make a hash of array references. The keys of the hash will
be the comment lines -- more specifically, the domains mentioned
there. The values in the hash will be array references of the lines for
that domain.
my $file = "...";
my %records;
open FILE, "+< $file" or die "can't r/w $file: $!";
while (<FILE>) {
next if /^#?$/; # skip empty lines and comment lines
# append to the list of records for a given domain
if (/(?:^|\@)(\S+)/) {
push @{ $records{$1} }, $_;
}
}
# rewind file
seek FILE, 0, 0;
# truncate file to 0 bytes
truncate FILE, 0;
# spit information out in readable form
for (sort keys %records) {
print FILE "#$_\n", @{ $records{$_} }, "\n";
}
close FILE;
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734