CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Reversing Scalars

 



Pro_4
User

May 14, 2001, 2:17 PM

Post #1 of 6 (595 views)
Reversing Scalars Can't Post

Hey,
I am creating a chat program solely based on Perl with nothing else and i was wondering if there was a way to reverse the scalars. The database is printed from oldest to newest and i want it the other way around. The viewing script is attached and you can check it out at my website and you will be able to understand a little bit better. http://etow.virtualave.net/chatroom.htm . Thanks for all the help

P.S. Let me make this clear i dont want to reverse the text were perl = lrep i want it to read the way it should be but from newest to oldest. :P
People Engrossed by a Reliable Language


(This post was edited by Pro_4 on May 14, 2001, 1:18 PM)


randor
User

May 14, 2001, 2:58 PM

Post #2 of 6 (591 views)
Re: Reversing Scalars [In reply to] Can't Post

ok, if what you expl;ained i understood, then try this:

take your scalars like so:

@scalars = (scalar1, scalar2, scalar3);
foreach $line (@scalars) {unshift(@scalars2, $line);
foreach $newline (@scalars2) {print "$newline\n";}

that will reverse the order from most recent on bottom to most recent on top.




Kanji
User / Moderator

May 14, 2001, 2:58 PM

Post #3 of 6 (591 views)
Re: Reversing Scalars [In reply to] Can't Post

Choose a better way of storing your data. :-)

If that isn't possible, then you'll need to use something like File::ReadBackwards, which you can implement yourself through appropriate use of seek and it's friends.


Code
  tie(*CHAT, File::ReadBackwards, "chat.txt") || die $!; 
while (<CHAT>) {
($name, $time, $post) = split(/\|/);
print "$name :$post \n";
}



randor
User

May 14, 2001, 3:01 PM

Post #4 of 6 (588 views)
Re: Reversing Scalars [In reply to] Can't Post

on my post above.. i used an array.. oops :) i guess i didnt read slow enough... but anyway.. it should work with scalars also with a little modifying..



Pro_4
User

May 14, 2001, 6:43 PM

Post #5 of 6 (585 views)
Re: Reversing Scalars [In reply to] Can't Post

Thanks i will try that.

Kanji how would you reccommend to store my data in a different way making it easier to access from newest to oldest?

Thanks :)

People Engrossed by a Reliable Language


Kanji
User / Moderator

May 15, 2001, 4:05 AM

Post #6 of 6 (581 views)
Re: Reversing Scalars [In reply to] Can't Post

A database, if you have access to one, although you could use what you have now in conjunction with DBD::CSV or DBD::RAM to get the same effect (ie, it'd treat them as if they were a database).

Alternatively, I'd suggest storing messages in forum/thread/message.txt format, and then you could call sort on the output of readdir(THREAD).


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives