Results 1 to 4 of 4

Thread: Writing a record to file; can't get a carriage return to produce separate record line

  1. #1
    Registered
    Join Date
    Aug 2009
    Location
    texas
    Posts
    26
    Rep Power
    0

    Writing a record to file; can't get a carriage return to produce separate record line

    I am reading and updating records in a simple flat file. I am creating a string to hold the updated record. I write the record with a "\n" following the string. I have tried this on my stand alone server and it works. When I try it on Powweb's server it doesn't recognize the carriage return.
    I decided to make a short script that reads the file, updates one record and write out the entire file again. It writes the records that were not changed correctly (one on each line) and the one I update does not have a carriage return. What am I missing? Thanks in advance!

    Here is the code:
    Code:
    open(INF,$fname) or dienice("Can't open $fname: $! \n");
    @booths = <INF>; 
    close(INF);
    $numentries = scalar(@booths); 
    
    ############  load the BOOTHLIST array that will hold the records for the boothfile by formname #############
    
    
    foreach $i (@booths) {
    
             ($booth, $slot1,$slot2,$slot3,$slot4, $formname) = split(/\|/, $i);
             $BOOTHLIST{$formname} = $i;
    }
    
       $bname = "facepaint";
        ($booth, $slot1,$slot2,$slot3,$slot4, $formname) = split(/\|/, $BOOTHLIST{$bname}); 
           $slot1 = $slot1 - 1; 
             $BOOTHLIST{$bname} =  $booth ."|". $slot1 ."|" . $slot2 ."|" . $slot3 . "|". $slot4 . "|" .$formname ."|";
    
    
        $fname = '>'.$filepath."booth-names-file.fle"; # append the correct directory path; overwrite entire file
    
        open (OUTF, $fname)  or dienice("Can't open $fname: $! for writing \n");
    
        foreach $key (keys(%BOOTHLIST)) {
          chomp ($BOOTHLIST{$key});
          print OUTF "$BOOTHLIST{$key}";
          print OUTF "\n";
    
        }
        close (OUTF);
    Last edited by IanS; 9-28-09 at 06:23 PM. Reason: Added code tags

  2. #2
    HalfaBee's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    7,266
    Rep Power
    26
    If you are outputting html you need to use "<br />\n"
    I don't suffer from laziness, I enjoy every minute!
    Edit your php.ini here
    http://members.powweb.com/member/cgi...nt/PHPplus.bml

  3. #3
    PowWeb Staff Dbrazzell's Avatar
    Join Date
    Nov 2008
    Location
    Burlington
    Posts
    489
    Rep Power
    20
    How are you viewing the file?

    If its in web browser. Check and see what the mime type is listed as.

    If its a .txt file our server might serve it up saying its text/plain or maybe it will say text/html

    this might cause your web browser to treat the file differently when viewed.

  4. #4
    Registered
    Join Date
    Aug 2009
    Location
    texas
    Posts
    26
    Rep Power
    0
    I am viewing the file with Notepad. The file extension is .fle. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •