You use substr to get 1st char even though ord returns numeric value of 1st char
You use split to get a list of individual characters and throw them away using a slice
I don't want to seem obstinate (I'm here for learning), but I made some tests:
#!/usr/bin/perl -w
use strict;
use Benchmark qw(:all);
my $str_a = "dlajsdlkajslkdjasldjasljdaskjd";
cmpthese(
-5,
{
'Test1' => sub { ord( $str_a ) },
'Test2' => sub { ord( ( split ( //, $str_a ) )[0] ) },
'Test3' => sub { ord( substr $str_a, 0, 1 ) },
}
);
__DATA__
Results:
Rate Test2 Test3 Test1
Test2 6321/s -- -99% -100%
Test3 516114/s 8065% -- -72%
Test1 1827646/s 28815% 254% --
I convene that isn't much readable, but it seems like the ord function works better with only one character as argument.
Update: I have misunderstood the result, sorry!
----------
kral
(sorry for my english)