Re: Perl ... unwanted space at start of line 2 onwards in file

by "Peter Newton" <c-newton(at)ihug.co.nz>

 Date:  Tue, 7 Mar 2000 11:10:06 +1300
 To:  <hwg-techniques(at)hwg.org>
 References: 
  todo: View Thread, Original
Thanks Brian and Terry

Yes the special variable $" LIST_SEPARATOR is the
cullprit and the suggested fix works a "beaut" as follows:-

$"='';                        #set LIST_SEPARATOR to NULL
print "@array/n";
$"=' ';                       #set LIST_SEPARATOR back to a space

same with the file printing

Many Thanks
Peter Newton

From: "Brian A. Sayrs" <sayrs(at)southwindsolutions.com>

What is happening is when you print your array, Perl automatically inserts
the LIST_SEPARATOR character into the output stream (gosh, it's helpful,
huh?).  The default value is a space, so what happens is that you print out
the line (plus the \n you put in), then it puts in the LIST_SEPARATOR then
continues onto the next line.

One way to solve this problem is to set LIST_SEPARATOR equal to nothing, and
it will work.  But be careful, because odd things might happen in other
parts of your program.

To do this, you can either put in this line:

$" = ''; # the rvalue is two single quotes...the lvalue is a dollar sign and
a double quote (because it affects double-quoted strings!)

or these two:

use English;
$LIST_SEPARATOR = '';  #  again, two single quotes

HTH,
Brian A. Sayrs
Owner, Southwind Solutions

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA