in reply to Why is print output different for function returning an array versus printing an array variable?

Because: print sort(@coins);

Uses $, (also known as $OUTPUT_FIELD_SEPARATOR (default value ' ' (space)) to separate items printed from a list. (The list returned by sort.)

Whereas: print "@coins";

Forces the array to be concatenated into a single string using $", (also known as $LIST_SEPARATOR, default value '' (null)).

Hence the former has spaces, but the latter has none.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: Why is print output different for function returning an array versus printing an array variable?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Why is print output different for function returning an array versus printing an array variable?
by Anonymous Monk on Oct 10, 2014 at 16:11 UTC
    You swapped the defaults.
Re^2: Why is print output different for function returning an array versus printing an array variable?
by aixtools (Novice) on Nov 06, 2014 at 14:00 UTC
    michael@x054:[/data/prj/labserv/perftools/perl]cat *2.pl @coins = ("Quarter","Dime","Nickel"); print "@coins"; print "\n\r"; print sort(@coins); print "\n\r"; michael@x054:[/data/prj/labserv/perftools/perl]perl *2.pl Quarter Dime Nickel DimeNickelQuarter

    Confused again. I seem to getting the opposite of what you said should happen. "@coins" is separated while sort(@coins) is not.

      I added one print statement - and now I understand the very literal impact of having an array in/not-in a string context.

      @coins = ("Quarter","Dime","Nickel"); print "@coins"; print "\n\r"; print @coins; print "\n\r"; print sort(@coins); print "\n\r"; Quarter Dime Nickel QuarterDimeNickel DimeNickelQuarter
      Again, thanks!!