Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: appending arrays

by davido (Cardinal)
on Nov 19, 2003 at 16:35 UTC ( #308333=note: print w/replies, xml ) Need Help??

in reply to appending arrays

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


"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].


    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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://308333]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2023-06-02 04:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found