Re: Flatfile database sorting in Perl

2002-11-18 Thread John W. Krahn
Gavin Laking wrote: > > One of my scripts uses a home-brewed flatfile database to store > information, and I've run up against a problem when I wish to sort > columns of data. > > An example of the database file: > (items,fruit,date) > > 16,apples,20021118-1725 > 22,bananas,20021118-1648 > 4,gra

RE: Flatfile database sorting in Perl

2002-11-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Here is one shot: while ( ) { chomp; # remove \n push(@dbfile, $_); } printf "Sort numerically:\n"; foreach my $MyData (sort {$a->[1] <=> $b->[1]} map{[$_, /^(\d+)/]} @dbfile) { printf "%-15s%5d: %-s\n", ' ', $MyData->[1], $MyData->[0]; } pri