in reply to printing to a file

When you're printing to the screen, you use
print @values;
and when you print to the file, you use
print NEW "@newfile";
See the quotes? They make a difference. In the former case, it's print that expands the array, and in the later case, it is the string interpolation.

Personally, I would say both methods are inadvisable: when you are printing arrays, determine their formating explicitly - for instance with a join.

Replies are listed 'Best First'.
Re: Re: printing to a file
by Fletch (Bishop) on Apr 02, 2004 at 18:45 UTC

    Or since it's CSV data use Text::CSV_XS and let it bother with quoting and what not.

Re: Re: printing to a file
by calin (Deacon) on Apr 02, 2004 at 19:06 UTC

    In addition...

    print uses $, as a "field separator" (the string which goes between elements of the argument list). String interpolation of arrays uses $" for the same purpose.

    The following one-liner prints the default value of these variables:

    $ perl -e 'print qq{\$,="$," \$"="$""\n}' $,="" $"=" "

    but when I print it to a text file, each value in the list has a space added to the front of it.

    Actually, the spaces are in between list elements