Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Trying to compare a string...

by kcott (Abbot)
on Oct 18, 2013 at 08:25 UTC ( #1058722=note: print w/ replies, xml ) Need Help??


in reply to Trying to compare a string...

G'day calebcall,

A non-empty string (except '0') will always be TRUE in a boolean context. So, 'Sci-Fi' will always be TRUE. Therefore, even if $genres[0] eq 'Science Fiction' was FALSE, $genres[0] eq 'Science Fiction' || 'Sci-Fi' would always be TRUE, and (with the short-circuiting nature of '||') || 'Fantasy' will never be tested.

The same will be true for those other conditions. You might want to consider something like this (untested):

my $genre = $genres[0]; for ($genres[0]) { /^(?:Science Fiction|Sci-Fi|Fantasy)$/ && $genre = 'Sci-Fi & Fanta +sy'; /^(?:Action|Adventure|War)$/ && $genre = 'Action & Adventure'; /^(?:Kids|Family)$/ && $genre = 'Kids & Family'; }

-- Ken


Comment on Re: Trying to compare a string...
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1058722]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-27 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls