in reply to variable sees it, array doesn't - stumped!

I find the Perl-magic for printing arrays confusing, so I always just specify exactly I want. How does print (join ' ', @array), "\n"; look?

Replies are listed 'Best First'.
Re^2: variable sees it, array doesn't - stumped!
by gone2015 (Deacon) on Dec 31, 2008 at 18:15 UTC
    print (join ' ', @array), "\n";

    ...sadly, Perl's syntax will have you for breakfast here... the brackets will be interpreted as delimiting the parameters of the print "function" -- see perlfunc.

      You are right: I thought I was using it someplace, but everywhere I've got it I put something else in before the output of the join.

      Either print((join ' ', @array), "\n"); or print (join(' ', @array)), "\n"; or even print join(' ', @array), "\n"; should work better.

        print (join(' ', @array)), "\n"
        Unfortunately, this one still doesn't work, for the same reason that print (join ' ', @array), "\n" doesn't. An option that I frequently use, though it feels dirty, is print '', (EXPR), "\n".
Re^2: variable sees it, array doesn't - stumped!
by shrdlu (Novice) on Dec 31, 2008 at 17:06 UTC
    It's true what they say then, there's always another way! Thanks for this, it does indeed look a little more intuitive.