Perl Tutorials -Part 32 – String comparison operators

Posted on May 27, 2010. Filed under: Perl Tutorials |


#example of perl if statement for string comparison.
$a = ‘sad’;
print ‘The string is not happy’ if $a ne ‘happy’;
print “\n\n”;

#example of unless statement for strings comparison
print ‘what an interesting word’ unless $a eq ‘happy’;

Output:

1
2
3
The string is not happy

what an interesting word
Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: