in reply to $" seems not to be working

$" is the record separator for arrays interpolated into double quoted strings. $, is the separator for print. perlvar for more info.

Replies are listed 'Best First'.
Re: Re: $" seems not to be working
by bart (Canon) on Mar 26, 2003 at 11:05 UTC
    To make it absolutely clear: you have to set $, to this effect, for the syntax you've used here, or you set $" and put the array slice in quotes. BTW you'd better use local on those variables, as they are globals, and they might influence the rest of your script, even the working of modules.
    { local $, = "|"; print @record[1..$fields]; }
    or
    { local $" = "|"; print "@record[1..$fields]"; }
    The default value of $" is a space, of $, it's the empty string — or undef, same thing here (no warnings).

    Note that the subscript of an array or a hash, or a ditto slice, is still evaluated as Perl code, at the time of interpolation. Thus, you can do calculations etc. there. Like:

    @number = qw(zero one two three four five six seven eight nine ten); print "The sum of $number[1] and $number[2] is $number[1+2].\n";

    The module Interpolation makes use of this little fact.