in reply to array join missing zero and space

Because that's not what join does.

Assuming you don't want a trailing space:

join ' ', map { 0, $_ } @numbers

Replies are listed 'Best First'.
Re^2: array join missing zero and space
by Gulliver (Monk) on Jun 21, 2011 at 13:40 UTC
    use strict; use warnings; my @numbers = (4,7,11,14); my $start='0 '; #print join ("$start" , @numbers),"\n"; print join ' ', map { 0, $_ } @numbers;

    The code above gives this:

    Not enough arguments for map at 910662.pl line 9, near "} @numbers" syntax error at 910662.pl line 9, near "} @numbers" Execution of 910662.pl aborted due to compilation errors.

    I tried this:

    print join ' ', map { ' 0 ' . $_ } @numbers;

    And get this:

     0 4  0 7  0 11  0 14

    Not sure where the extra spaces after 4,7 and 11 come from.

    Update: duh, the join has a space.

      Brackets are needed to make the mapping function return a 2-element list for each element of @numbers, which is what I think ikegami intended:

      print join ' ', map { (0, $_) } @numbers;

      --

      "Any sufficiently analyzed magic is indistinguishable from science" - Agatha Heterodyne

      bah, the parser is thinking {} is a hash constructor instead of a block. A semi-colon will disambiguate.
      print join ' ', map {; 0, $_ } @numbers;