What is the proper way to check if a string is empty in Perl? -


i've been using code check if string empty:

if ($str == "") {   // ... } 

and same not equals operator...

if ($str != "") {   // ... } 

this seems work (i think), i'm not sure it's correct way, or if there unforeseen drawbacks. doesn't feel right it.

for string comparisons in perl, use eq or ne:

if ($str eq "") {   // ... } 

the == , != operators numeric comparison operators. attempt convert both operands integers before comparing them.

see perlop man page more information.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -