#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Data::Dumper; # TODO turn into yml as an external file. my @index = ( { keywords => [ qw/ emacs cfengine_el / ], topic => "Cfengine_el is an EMACS plugin to edit your CFEngine ". "code: ". "https://github.com/cfengine/core/blob/master/contrib/cfengine.el", }, { keywords => [ 'best practices' ], topic => "CFEngine best practices: ". "http://evolvethinking.com/category/cfengine/best-practices/". "and https://github.com/atsaloli/cf-health-check", }, ); my %topic; my %keyword; my $i = 0; # Build a fast index for keyword searches for my $next_topic ( @index ) { # Store topic in index. $topic{$i} = $next_topic->{topic}; for my $next_keyword ( @{ $next_topic->{keywords} } ) { # Store keyworkd in index. $keyword{$next_keyword} = $i; } $i++; } say Dumper( \%topic ); say Dumper( \%keyword ); say 'topic for keyword "best practices" is ' . $topic{ $keyword{ 'best practices' } }; #### $VAR1 = { '0' => 'Cfengine_el is an EMACS plugin to edit your CFEngine code: https://github.com/cfengine/core/blob/master/contrib/cfengine.el', '1' => 'CFEngine best practices: http://evolvethinking.com/category/cfengine/best-practices/and https://github.com/atsaloli/cf-health-check' }; $VAR1 = { 'emacs' => 0, 'cfengine_el' => 0, 'best practices' => 1 }; topic for keyword "best practices" is CFEngine best practices: http://evolvethinking.com/category/cfengine/best-practices/and https://github.com/atsaloli/cf-health-check