in reply to Re: array join missing zero and space
in thread array join missing zero and space

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.

Replies are listed 'Best First'.
Re^3: array join missing zero and space
by mykl (Monk) on Jun 21, 2011 at 13:51 UTC

    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

Re^3: array join missing zero and space
by ikegami (Patriarch) on Jun 21, 2011 at 16:32 UTC
    bah, the parser is thinking {} is a hash constructor instead of a block. A semi-colon will disambiguate.
    print join ' ', map {; 0, $_ } @numbers;