NicoleSwan.com

I like to ride my bike.

perl tips in case you tend to forget things like I do

Posted on | January 15, 2004 |

So, you want to test string equality in Perl? You just use ‘==’ right? Wrong. In Perl, that will only test number equality which could cause a few problems and inconsistencies.

The Wrong Way:

$mystring = "";

# wrong way
if ( $mystring == "" )
{
      print $mystring; #will never print
}

The Right Way

$mystring = "";
$mystring2 = "foo";

if( $mystring eq "" )
{
      print $mystring; #will print
}

#the 'not equals' counterpart
if ( $mystring2 ne "")
{
      print $mystring2; #will print
}

And a helpful link for good measure.

Comments

Comments are closed.

Dreams

To live in a bike friendlier world. To create the greatest collection of fabulous shoes ever assembled. To see a viable third party in US politics. To get local Rio team riders to acknowledge existence on road.

Get the feed

Search

  • Worth Reading