in reply to Ordering data in a file.

Read data into a hash-of arrays data structure, then sort it:
use warnings; use strict; my %data; my $key; while (<DATA>) { chomp; if (/#(\d+)/) { $key = $1; } else { push @{ $data{$key} }, $_; } } for my $key (sort {$a <=> $b} keys %data) { print "#$key\n"; print "$_\n" for @{ $data{$key} }; } __DATA__ #12346 orange #12345 apple banana #12344 pear

Replies are listed 'Best First'.
Re^2: Ordering data in a file.
by Anonymous Monk on Jun 13, 2013 at 19:39 UTC
    Thanks a lot .. it worked instantly!!!