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:
My array is sloping off on me....

 



seriousfun
Novice

Jun 17, 2001, 1:14 AM

Post #1 of 3 (471 views)
My array is sloping off on me.... Can't Post

I am trying to update a log file but maintain it at a set length. I am endevouring to remove the bottom item from the array and put a new one on the top. The code I am using is

open (TXTFILE, "$data");
@lines = <TXTFILE>;
close(TXTFILE);

shift (@lines);
open (LOG, ">$data");
print LOG "@lines";
print LOG "$newstuff\n";
close (LOG);

This seems to work well enough except that the resulting file shows a sloping array . A copy of the array is below. The fullstops are not there I have placed them in simply to ensure that the correct spacing shows in this message.

......entry
......another
....yet another
.. one more
latest entry

I cannot work out what is causing the entries to be out of align with each other except that it is obviously something in my code.

Any help would be appreciated.



randor
User

Jun 17, 2001, 3:43 AM

Post #2 of 3 (464 views)
Re: My array is sloping off on me.... [In reply to] Can't Post

seriousfun,

i did not test this, but try it, i had this very same problem once, and i was advised to remove the quotes from my print statement.. i really do not understand why it worked but in my case it did, so it cant hurt for you to try it.


open (TXTFILE, "$data");
@lines = <TXTFILE>;
close(TXTFILE);

shift (@lines);
push(@lines, $newstuff);
open (LOG, ">$data");
print LOG @lines;
close (LOG);

I Hope this helps...

perl programmers don't die.. they just start writing a new script.


seriousfun
Novice

Jun 17, 2001, 4:00 AM

Post #3 of 3 (462 views)
Re: My array is sloping off on me.... [In reply to] Can't Post

You were spot on with that answer. Thanks for helping, I could have spent 10 life times working that one out .


 
 


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

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