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. Concatenate 284 and 9 to get 2849, 284 and 10 to get 28410, which comes before 2849 in sting compare. Using sprintf("%4d",...) - " 284 9" is compared to " 284 10" and works properly in this context.
What is "void context"?
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
