in reply to Where am I going wrong with printing flatfile db records in alphabetical order?

To be honest, your code really doesn't make much sense. Here's how I'd do it:

open DATABASE, $mydata or die "Can't open $mydata: $!\n"; flock DATABASE, LOCK_EX or die "Can't lock $mydata: $!\n"; my @list = <DATABASE>; close DATABASE; # which also unlocks it @list = sort { substr($a, 0, 8) cmp substr($b, 0, 8) } @list;

At the end of this code, @list contains the data in sorted order.

Update: Ovid is right, of course. Corrected.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you don't talk about Perl club."

Replies are listed 'Best First'.
(Ovid) Re(2): Where am I going wrong ?
by Ovid (Cardinal) on Oct 29, 2001 at 21:04 UTC

    If you need the first eight characters, I believe you want substr($foo, 0, 8) and not substr($foo, 8, 0). :)

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.