Frank Bax wrote:
> At 02:11 PM 10/23/05, John W. Krahn wrote:
> 
>> Frank Bax wrote:
>> >         my $snew =
>> > sprintf("%4d%4d",$aSuit{$new}{'rescap'},$aSuit{$new}{'resval'});
>> >         my $slow =
>> > sprintf("%4d%4d",$aSuit{$low}{'rescap'},$aSuit{$low}{'resval'});
>>
>> Using sprintf() to concatenate numbers is (AFAIK) going to be slower than
>> concatenation:
>>
>>         my $snew = $aSuit{ $new }{ rescap } . $aSuit{ $new }{ resval };
>>         my $slow = $aSuit{ $low }{ rescap } . $aSuit{ $low }{ resval };
>>
>> >     my $aval=''; map { $aval=$aval.sprintf("%4d",$aSuit{$a}{$_}); }
>> @f_seq;
>> >     my $bval=''; map { $bval=$bval.sprintf("%4d",$aSuit{$b}{$_}); }
>> @f_seq;
>>
>> You shouldn't use map in void context, you should use a foreach loop
>> instead,
>> but you don't even need a loop there:
>>
>>     my $aval = join '', @{ $aSuit{ $a } }{ @f_seq };
>>     my $bval = join '', @{ $aSuit{ $b } }{ @f_seq };
> 
> 
> Your suggested code changes don't work when the list of numbers on each
> side of comparison have different number of digits - that's why I
> initially introduced sprintf - so all numbers would use 4
> digits/characters.

    my $format = '%4d' x @f_seq;
    sprintf( $format, @{ $aSuit{ $a } }{ @f_seq } ) cmp sprintf( $format, @{
$aSuit{ $b } }{ @f_seq } );



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to