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

Hi Monks, I will try to use 'OUTPUT_FIELD_SEPARATOR' in different ways. Now I am facing problem, that is 'OUTPUT_FIELD_SEPARATOR' is not working inside Double quotes.

Sample code:

@files=('apple','ball','cat','dance'); $,="\n"; ###Below line OUTPUT_FIELD_SEPARATOR is working print "\nArray Elements in Outoff Double Quotes :", @files; ###Below line OUTPUT_FIELD_SEPARATOR isnot working print "\nArray Elements within Double Quotes :\n@files";

I know this question is silly, but I need to know the fact.

Thanks in advance.

Regards,
Velusamy R.

Replies are listed 'Best First'.
Re: Problem in OUTPUT_FIELD_SEPARATOR
by poj (Abbot) on Aug 27, 2005 at 08:04 UTC
    Another variable needs to be set
    $LIST_SEPARATOR $" This is like $, except that it applies to array and slice values interpolated into a double-quoted string ( or similar interpreted string). Default is a space.
    poj
Re: Problem in OUTPUT_FIELD_SEPARATOR
by BrowserUk (Patriarch) on Aug 27, 2005 at 08:04 UTC

    $OUTPUT_FIELD_SEPARATOR only operates on comma separated fields, not arrays interpolated within double quotes. For that, you need to use $LIST_SEPARATOR.

    $" = "\n"; ## This may do what you intended. print "\nArray Elements within Double Quotes :\n@files";

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

      Thank you for your replies. But I have one more question is "For What reason Variable Interpolation is not working in second print statement in my code".

      Regards,
      Velusamy R.

        Is working the it is supposed to work - perlvar:
        "$, The output field separator for the print operator.
        Ordinarily the print operator simply prints out its arguments without further adornment."
        .
        ... print "\nArray Elements within Double Quotes :\n", @files; ... output: Array Elements within Double Quotes : apple ball cat


Re: Problem in OUTPUT_FIELD_SEPARATOR
by spiritway (Vicar) on Aug 27, 2005 at 08:02 UTC

    I don't think it's a silly question. I suspect (though I don't know for certain) that in the context of a double quote, the @files array isn't considered a set of fields, and so is printed as a straight array. I could see there being a distinction made between data outside the quotes, and inside. I don't know whether this is a feature, though.