Samn has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: \n and \r
by theguvnor (Chaplain) on Mar 09, 2002 at 13:58 UTC

    Hi Samn.

    It took me a few seconds to realize what was going on here, but you need to use <code> tags when you post. Otherwise, any HTML entities don't get encoded properly and so you get results like line 2 of your program, which looks like "@log = ;".

    Anyway, the reason for the spaces is that you have put double quotes around your @log array. When an array is interpolated into a string, perl automagically does a join with the default record separator, which also happens to default to a space.

    Just do print FILE @log; and you should be fine.

    Update ++jeffa for correcting my hasty from-memory-explanation :)

    ..Guv

      "When an array is interpolated into a string, perl automagically does a join with the default record separator, which also happens to default to a space."

      Close.

      The 'default record separator' (i think you mean the input record separator, $/, which defaults to a new line) is not used here, instead the list separator ($", which defaults to a space) is used. See perlvar for more. Also, page 13 of Network Programming w/ Perl lays out the scoop on end-of-line characters. If you don't have a copy (which you should), you can read a watered-down version of that discussion here: A Little History on 0D0A.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
Re: \n and \r
by erikharrison (Deacon) on Mar 09, 2002 at 16:26 UTC

    As for generating a newline \n should be sufficient - Perl will make it a newline for you. Since operating systems differ on what a newline is, using \n will make your program more portable.

    Cheers,
    Erik
150557
by Samn (Monk) on Mar 09, 2002 at 13:33 UTC