Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Trying to compare a string...

by moritz (Cardinal)
on Oct 18, 2013 at 08:26 UTC ( [id://1058723]=note: print w/replies, xml ) Need Help??


in reply to Trying to compare a string...

In addition to choroba's excellent answer, I'd like to point out that you can replace code with data like this:

my %genre_map = ( 'Science Fiction' => 'Sci-Fi & Fantasy', 'Sci-FI' => 'Sci-Fi & Fantasy', 'Fantasy' => 'Sci-Fi & Fantasy', 'Action' => 'Action & Adventure', ... ); my $genre = $genre_map{$genres[0]} // $genres[0];

Factoring the code like this would even allow you to put the genre mapping into a configuration file, and load the hash from it.

Finally, Perl 6 has a feature called junctions which does allow you to write code similar to what you tried:

use v6; my $genre; my @genres = 'Kids', 'Ignored'; 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]; } say $genre;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found