sweepy838 has asked for the wisdom of the Perl Monks concerning the following question:
with the map function im trying to push each value into the names array starting at offset 6 in the @input2arr array. here is how it would be done without map:$input = ':xxx xxxxx = #xxx :xxx @rndletters @rndletters'; @input2arr = split / /, $input; my @names = map {$i > 6 ? push(@names,$input2arr[$i]) : $i++ } @input2 +arr;
my $i = 0; my $input = ':xxx xxxxx = #xxx :xxx @rndletters @rndletters'; my @names; my @input2arr = split //, $input; for my $str (@input2arr) { if ($i > 6) { push (@names, $str); } $i++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: bit of help with map function
by moritz (Cardinal) on Apr 30, 2012 at 18:53 UTC | |
|
Re: bit of help with map function
by MidLifeXis (Monsignor) on Apr 30, 2012 at 18:53 UTC | |
|
Re: bit of help with map function
by toolic (Bishop) on Apr 30, 2012 at 18:37 UTC | |
|
Re: bit of help with map function
by kennethk (Abbot) on Apr 30, 2012 at 18:39 UTC | |
|
Re: bit of help with map function
by tobyink (Canon) on Apr 30, 2012 at 21:33 UTC | |
by sweepy838 (Acolyte) on Apr 30, 2012 at 22:06 UTC |