On Tue, Jun 12, 2001 at 05:14:19PM +0100, Martin van-Eerde wrote:
> Thanks for any help!
>
> my @first = qw(high medium low apex);
> my @second = qw(100.00 50.50 34.25 23.99);
>
>
> my $idx = -1;
> my @result = map {$idx ++; $second[$idx].'~'.$_} @first;
>
> print "merge result:\n";
> print join "\n", @result;
> print "\n";
>
> print sort {split( "~", $a) <=> split( "~", $b)} @result;
To fix the minimum number of problems here change your print statement:
print sort { (split "~", $a)[0] <=> <=> (split "~", $b)[0] } @result;
Recall, split returns an array, so evaluating it as a scalar is probably not
what you want.
However, joining and then later splitting your data is suboptimal.
my $idx = -1;
my @result = map { $idx++; [$second[$idx], $_] } @first;
# print...
print sort { $a->[0] <=> $b->[0] } @first;
Of course, printing @result will require another map.
To be really compact:
my $idx = -1;
print sort { $a->[0] <=> $b->[0] }
map { $idx++; [$second[$idx], $_] } @first
The change in both latter cases is that @result (in the second example
@result isn't explicit, but the map returns what amounts to @result) is an
array of arrays.
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--