calebcall has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to compare a string, and for some reason it will always match the first stanza even though it really doesn't. Here's is my compare:
Some debug output is:if ($genres[0] eq 'Science Fiction' || 'Sci-Fi' || 'Fantasy') { $genre = 'Sci-Fi & Fantasy'; }elsif ($genres[0] eq 'Action' || 'Adventure' || 'War') { $genre = 'Action & Adventure'; }elsif ($genres[0] eq 'Kids' || 'Family') { $genre = 'Kids & Family'; }else { $genre = $genres[0]; }
The output looks like:print "Genres: $genres[0]\n"; print "Genre: $genre\n";
Genres: Action Genre: Sci-Fi & Fantasy
If I move say Kids & Family to the first block, it always ends up being Kids & Family. Any idea what I'm doing wrong that would cause it to always match that first block?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Trying to compare a string...
by choroba (Cardinal) on Oct 18, 2013 at 08:10 UTC | |
Re: Trying to compare a string...
by moritz (Cardinal) on Oct 18, 2013 at 08:26 UTC | |
Re: Trying to compare a string...
by kcott (Archbishop) on Oct 18, 2013 at 08:25 UTC | |
Re: Trying to compare a string...
by hdb (Monsignor) on Oct 18, 2013 at 08:49 UTC | |
Re: Trying to compare a string...
by tobyink (Canon) on Oct 18, 2013 at 10:43 UTC |
Back to
Seekers of Perl Wisdom