>
>     @list1 = qw( artist awful billy blunder)
>     @list2 = qw( attitude blatherskite)
>
>     # something magical happens, and the contents of @list1 are now
>     # 'artist', 'attitude', 'awful', 'billy', 'blatherskite', 'blunder'
>
> If the lists aren't too large, here's what I'd do:
>
> @list1 = (@list1, @list2);
> @list1 = sort (@list1);

The obvious down side of this is your not taking advantage of the fact that list1 and list2 are already sorted.
But if like you said they are each small no big deal, if each list is a million lines you might want to take a shot at doing a compare / merge, it would be a straight line function that can get short circuited if one list ends long before the other since as soon as one list is empty you can add the entire other list at the end.

As I understand you have changed the rules but something like this might give you a nudge in the right direction.

use warnings;
use strict;

my @list1 = qw( artist awful billy blunder);
my @list2 = qw( attitude blatherskite);
my @list3;

while(@list1 and @list2){
   if ( $list1[0] le $list2[0] ){
      push @list3,$list1[0];
      shift @list1;
   } else {
      push @list3,$list2[0];
      shift @list2;
   }
}
@list3 = (@list3,@list1) if (@list1);
@list3 = (@list3,@list2) if (@list2);
print "@list3\n";
     
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to