Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: Reconciling multiple lists (similar to "merge" in CVS?)

by japhy (Canon)
on Jan 06, 2007 at 16:11 UTC ( #593305=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Reconciling multiple lists (similar to "merge" in CVS?)
in thread Reconciling multiple lists (similar to "merge" in CVS?)

Re: your "XXX" block, I've refactored the code thus:

# 0 --> identical element if ( $which_list == 0 ) { die "Can't happen" if @indices1 != @indices2; foreach my $i ( 0 .. $#indices1 ) { my ( $item1, @offsets ) = @{ $list1_aref->[ $indices1[ +$i] ] }; my ( $item2, $offset ) = @{ $list2_aref->[ $indices2[ +$i] ] }; die unless $item1 eq $item2; push @offsets, $offset; push @merged, [ $item1, @offsets ]; } } # 1 --> list 1 has an element here if ( $which_list & 1 ) { foreach ( @{ $list1_aref }[ @indices1 ] ) { my ( $item1, @offsets ) = @{ $_ }; push @offsets, undef; push @merged, [ $item1, @offsets ]; } } # 2 --> list 2 has an element here if ( $which_list & 2 ) { foreach ( @{ $list2_aref }[ @indices2 ] ) { my ( $item2, $offset ) = @{ $_ }; my @offsets = map { undef() } 1 .. $offset_width; push @offsets, $offset; push @merged, [ $item2, @offsets ]; } }
I've scrapped the 'elsifs' and used & instead of ==.

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart


Comment on Re^4: Reconciling multiple lists (similar to "merge" in CVS?)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2015-07-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls