This little code works fine it just keeps generating numbers and writing
them to a data base.
#!/usr/bin/perl print "Content-type: text/html\r\n\r\n"; ### Generate some numbers. $now = time(); $nill = time() + 50; $null = time() + 100; ### Then print to prove that worked print "<br><b>Line one from mixed.data = $now"; print "<br><b>Line two from mixed.data = $nill"; print "<br><b>Line three from mixed.data = $null"; ### Fine -- So now I make an array @scale = ($now,$nill,$null); ### And print to prove that works print "<br><b> Print Array = @scale"; ### Fine ### Then I overwrite mixed.data with $data_path = "data/mixed.data"; open(O, ">$data_path"); print O join("\n",@scale),"\n"; close(O);
Now thats all fine writing to mixed data perfectly. However I have a small circle of code that wont behave itself. the simple database ( mixed.dat )just containes
FAST
FASTER
FASTEST
#!/usr/bin/perl print "Content-type: text/html\r\n\r\n"; ### First I read from database. $data_path = "data/mixed.data"; open(DAT, $data_path) || die("Could not open file!"); @rawdata=<DAT>; close(DAT); $now = $rawdata[0]; $nill = $rawdata[1]; $null = $rawdata[2]; ### Then print to prove that worked print "<br><b>Line one from mixed.data = $now"; print "<br><b>Line two from mixed.data = $nill"; print "<br><b>Line three from mixed.data = $null"; ### Fine so far-- So now I make an array @scale = ($now,$nill,$null); ### And print to prove that works print "<br><b> Print Array = @scale"; ### This results in browser. #----------------------------------- # Line one from mixed.data = FAST # Line two from mixed.data = FASTER # Line three from mixed.data = FASTEST # Printed from Array = FAST FASTER FASTEST #------------------------------------ ### Which is all very fine so far. ### Then I overwrite mixed.data with $data_path = "data/mixed.data"; open(O, ">$data_path"); print O join("\n",@scale),"\n"; close(O);
Which results in mixed.data file being written as

FAST

FASTER

FASTEST
With new line entries
The next time I run the script the data base will be written as
FAST


FASTER

with double line entry and FASTEST has dissapeared
The next time I run it only FAST remains.
Oh-- How confusing!
All I want it to do is just keep repeating the database.
As the first little script dose.
Why you may ask.?
Well if I can get it to repeat the database with the array involved
I can then move some element of the array.
I think it is all to do with \n somwhere.
But I cant find it.
God Bless anyone who can.

jdporter added readmore tags


In reply to Vicious circle. by nasa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.