[Perl] most efficient
Gabor Szabo
gabor at tracert.com
Tue Dec 10 17:06:58 EET 2002
On Tue, 10 Dec 2002, Shlomo Yona wrote:
> Hello,
>
> What would be an efficient way to check if some scalar $string
> contains the character $character as it's first character?
>
> I bet there are better ways than this:
>
> if ($string=~/^$character/) {
> # do something
> }
This is another case when pattern matching should NOT be used.
if (substr($string,0,1) eq $character) {
# rm -rf /
}
Gabor
ps. this does something, doesn't it ? :-()
More information about the Perl
mailing list