in reply to RE: RE: Writing the contents of an array to a file
in thread Writing the contents of an array to a file

FYI, $" is to print "@list" as $, is to print @list or print $a, $b, $c
@a = qw{ one two }; @b = qw{ tre for }; { local $" = "-"; print "@a @b"; # one-two tre-for } { local $, = "-"; print @a, @b; # one-two-tre-for local $" = ":"; print "@a", "@b"; # one:two-tre:for }
Cheers

Replies are listed 'Best First'.
(tye)RE: Writing the contents of an array to a file
by tye (Sage) on Sep 29, 2000 at 00:06 UTC

    Note also that while each pair of lines of code below produce the same output:

    print FILE "@array"; print FILE join $", @array; print FILE @array; print FILE join $,, @array;
    they are not equivalent in terms of performance. Only print FILE @array avoids building a potentially huge string in memory before writing. In practice, the speed improvement is usually small (or even negative) but I prefer to allow for huge arrays and avoid the join if I'm just going to write the result to a file and then throw the constructed string away.

    Though I do find appealing the way that using join prevents your code from breaking if you accidentally sneak a scalar context into the mix (typing a "." when you meant a ",", for example).

            - tye (but my friends call me "Tye")