Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Apr 262010
 

Faster string length testing in PHP

Answer:

If you want to ensure a string variable has a particular length, you might use strlen


if ( strlen($str) > 10 ) {
    // ...
}

A faster approach is to use isset


if ( isset($str[10]) ) {
    // ...
}
Apr 252010
 

eq vs == in Perl

Answer:

1. eq

It perform string comparison.

my $foo = "123";
my $bar = "123";

print $foo eq $bar; # output "1"

2. ==

It perform numeric comparison, string is first converted to numeric value before compare.

my $foo = "foo";
my $bar = "bar";

print $foo == $bar; # output "1", since 0 = 0 as strings are converted to 0 in both variables