There are many ways...
sub getchar_unpack { my ($string, $index) = @_; return unless $index >= 0 and $index < length($string); return chr( (unpack 'C*', $string)[$index] ); } sub getchar_split { my ($string, $index) = @_; return unless $index >= 0 and $index < length($string); return ( (split //, $string)[$index] ); } sub getchar_loop { my ($string, $index) = @_; return unless $index >= 0 and $index < length($string); $string = reverse $string; my $c; $c = chop $string until $index-- == 0; return $c; }
But why?
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Get char in string
by sauoq
in thread Get char in string
by PerlLoveMe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |