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

While you can perfectly say, split //, $scalar and get the result you want, why is it that join //, @array puts in a "1" between the characters?
say,
> perl -e 'print join(//,qw(a b c)), "\n"'

Output:
a1b1c

Replies are listed 'Best First'.
Re: An observation on join
by moritz (Cardinal) on Sep 21, 2011 at 07:18 UTC

    If you were developing the Perl programming language, how would you write a join() function that works with a regex as separator? What would it do?

    I find that it is often helpful to imagine myself being in a different role, looking at a problem from a different perspective.

      Hey Thanks! That's much better a way to understand that than having to memorize a rule from perldoc.

      Well put! I never bothered thinking about it, but that makes perfect sense. Using a regex for a join would be like saying "get me a food".

Re: An observation on join
by ranga17 (Novice) on Sep 21, 2011 at 06:07 UTC
    Sorry guys.
    perldoc clearly says " Beware that unlike split, join doesn't take a pattern as its first argument. ". It is evaluating // to 1 and using that as the expr to join.
Re: An observation on join
by Anonymous Monk on Sep 21, 2011 at 08:42 UTC
    Try with this:
    perl -e "print join(/ /,qw(a b c))"