Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting file

Status
Not open for further replies.

PhoenixDown

Programmer
Jul 2, 2001
279
CA
I'm trying to make a script to do this:

sort.jpg


How can I do that?

Thanks. Please post an example.
 
I would get the entries into an array. You didn't mention where the entries are stored, but I'll assume it is in a file. Assuming the newer entries are at the bottom of the file.
Code:
open(FILE, "$file") or "Can't open $file: $!\n";
@BottomToTop = (<FILE>);
close(FILE);
@TopToBottom = reverse(@BottomToTop);
 
The entries are stored in a flatfile DB:

1|test|tset|test
2|test|tset|test
3|test|tset|test
4|test|tset|test
5|test|tset|test

Yes, right now, newer guestbook entries are at the bottom. :)
 
You don't need to sort file each time you add entry.
just append the file.

open ( FH , &quot;$file&quot;) or die 'can not open file' ;

@entries = (<FH>);

while($entry = pop(@entries) ){
.....you will get entries from bottom of the file .....
print $entry ,&quot;\n&quot;;
}



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top