Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LadyAleena/c16b8fa146749a65eeb0dfac94525b7e to your computer and use it in GitHub Desktop.
Save LadyAleena/c16b8fa146749a65eeb0dfac94525b7e to your computer and use it in GitHub Desktop.
my $movies_data = movie('data');
my $search;
my @movies;
if ( $title || $year || $media || $genre || $source || $alpha ) {
my @selections;
push @selections, $title if $title;
push @selections, $year if $year;
push @selections, $media if $media;
push @selections, $genre if $genre;
push @selections, $source if $source;
my $selection = @selections ? grammatical_join('and', map("<b>$_</b>", @selections)) : '';
my $selection_text = $selection;
for my $movie (values %$movies_data) {
my $item = $movie->{'title'};
if ($year) {
my $start_year = start_year($movie);
my $end_year = end_year($movie);
if ($start_year !~ /\d/ || $end_year !~ /\d/) {
if ($start_year ne $year || $end_year ne $year) {
next;
}
}
else {
if ($year < $start_year || $year > $end_year) {
next;
};
}
}
next if $media && $movie->{'media'} ne $media;
next if $genre && !$movie->{'genre'}{$genre};
next if $source && (!$movie->{'source'} || $movie->{'source'} !~ /\b$source(?!ing)/i);
next if $title && lc($movie->{'title'}) !~ /\L$title\E/i;
next if $alpha && first_alpha($movie->{'title'}) ne $alpha;
push @movies, $movie->{'title'};
}
$search = @movies > 0 ? "You searched for $selection_text in my collection." : "No matches found for $selection_text.";
}
else {
@movies = keys %$movies_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment