And as this is the Perl beginners list, please don't top post.

2008/4/24 Andrew Curry <[EMAIL PROTECTED]>:
> As this is a beginners list are you going to explain...
>
>
>     push my @c, [EMAIL PROTECTED] @a}];
>     push @{$c[0]}, (@{shift @b})[1];
>
>     $c[$_->[0]] = [ @{$_} ] while $_ = shift @a;
>     push @{$c[$_->[0]]}, $_->[1] while $_ = shift @b;
>

Sure:

    perldoc -f push
    perldoc -f shift
    perldoc -f while
    perldoc perlreftut.

The real answer to your question, though, is that the sort of
explanation I think your looking for--you didn't actually say what you
would like explained or what part of my code you had trouble
understanding--is really OT for this thread. OP is, demonstrably,
already familiar with references, or at least his example code uses
them effectively. I'm going to go out on a limb and assume that he's
familiar with push, shift, and while, as well. I've just suggested a
different way to string them together. If he has a question about how
something works, he'll ask.

If you have a question about parsing complex refernces, you'd be
better off starting a new thread on understanding references. Say that
you've stared at it for a while, and "push @{$c[$_->[0]]}, $_->[1]
while $_ = shift @b" still doesn't make sense to you. The people who
would be most interested in answering a question like that may not
find it buried in a thread on merging AoAs.


Why don't you let us know which part of the code you're having trouble
with, though, and someone will try to explain it. It's difficult to
answer a question that hasn't been asked.


If your question is what I think it is, though, try working through
the statements backwards. Take


     $c[$_->[0]] = [ @{$_} ] while $_ = shift @a;

It's a while loop. On each pass though, what's in $_? Then what must
be in $_->[0]? Given that, what must $c[$_->[0]] refer to? Here's a
hint: I told OP that the index of the merged array and the first
element of the reference both store the id.

Once you understand that,

    push @{$c[$_->[0]]}, $_->[1] while $_ = shift @b;

should be clearer, too.


HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org

values of β will give rise to dom!

Reply via email to