http://qs321.pair.com?node_id=308333


in reply to appending arrays

my $a2count = $#array2; my @newarray; for (my $a1count = 0; $a1count<@array1; @a1count++ ) { push @newarray, @array1[$a1count] . @array2[$a2count--]; }


Dave


"If I had my life to live over again, I'd be a plumber." -- Albert Einstein

Replies are listed 'Best First'.
Re: Re: appending arrays
by kelan (Deacon) on Nov 19, 2003 at 18:29 UTC

    Here's a similar way, without initializing either counter:

    push @new, $array1[$count1++].$array2[--$count2] while ($count1 < @array1 && -$count2 < @array2);
    By the way, your array accesses are using 1 element slices instead of direct element access. Consider changing @array1[$a1count] to $array1[$a1count].

    kelan


    Perl6 Grammar Student

(stop senseless node rewriting)Re: Re: appending arrays
by Anonymous Monk on Nov 19, 2003 at 16:53 UTC

    davido Please refrain from wholesale rewriting of node content! Minor edits should at least be acknowledged, and total replacement of content should only be done in extreme circumstances (which I can not think of any at the moment). Update your nodes, stop just rewriting them. Please. This is not the first time you've changed a nodes content out from under me just before I posted a reply, rendering the reply, which could have been instructive both to yourself and to others, totally without context.

    A reply falls below the community's threshold of quality. You may see it by logging in.