#!/usr/bin/perl -w
@t = qw( aaaa bbbb ccccccc dddddd );
# assumes $i is undef or == 0
@n = map {$i+=5." ".$_} @t;
print map {$_."\n"} @n;
Odd, starting at 1, but not divisible by 5:
#!/usr/bin/perl -w
@t = qw( aaaa bbbb ccccccc dddddd );
$i = -1;
# the 2nd semicolon is not required, but adds clarity
@n = map {$i+=2; if ($i%5==0){$i+=2}; $i." ".$_} @t;
print map {$_."\n"} @n;
Your examples seem to indicate that you misunderstand the use of map. For example, your
@newwords = map {$l % 5 == 0; $l," ",$_} @words;
There's a test of $l, but nothing happens no matter the result. The $l," ",$_ might make sense as an argument to the print command, but not here. If it were $l." ".$_ then @newwords would be filled with items consisting of the value of $l followed by a space followed by an item from @words.
However, $l would not be changed so every @newwords item would have the same number. |