If we play with the definition of "first character", Perl will match a number at the beginning of a string:
$_ = "13foo"; if($_ == 13) { print "Works\n"; } __OUTPUT__ Works
But doing it under warnings gives you Argument "13foo" isn't numeric in numeric eq (==). The ++ operator also has some DWIM magic involved for incrementing strings that begin with numbers (but -- doesn't).
For any strings, you can also use split like this:
my ($first, $rest) = split '', $str, 2;
You can also play string reversal tricks, if you don't mind modifying the string:
$_ = reverse $str; print chop;
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
In reply to Re: Matching First Character of Strings Efficiently
by hardburn
in thread Matching First Character of Strings Efficiently
by Limbic~Region
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |