Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Where am I going wrong ?

by Albannach (Monsignor)
on Oct 29, 2001 at 19:51 UTC ( [id://121927]=note: print w/replies, xml ) Need Help??


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

You need to actually call sort if you want something sorted ;-)

You need to sort the whole @list and then loop through to print if that's what you're after. Since you are sorting by the first field anyway, why bother with the 8 character restriction? I'd think that just adding @list = sort @list; before your printing loop should do what you want.

--
I'd like to be able to assign to an luser

Replies are listed 'Best First'.
Re: Re: Where am I going wrong ?
by caciqueman (Novice) on Oct 29, 2001 at 22:31 UTC
    Thanks, this worked:
    @list = sort @list;

      Not to beat a dead horse too much, but is there any reason not to simply sort the list as it's read (which conserves memory, if THAT matters here)? To wit:

      open DATABASE, $mydata or die "Can't open $mydata: $!\n"; flock DATABASE, LOCK_EX or die "Can't lock $mydata: $!\n"; my @list = sort <DATABASE>; # NOTE ^^^^ close DATABASE; # which also unlocks it

      dmm

      
      You can give a man a fish and feed him for a day ...
      Or, you can teach him to fish and feed him for a lifetime
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://121927]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found