Perl Weekly Challenge W024 - Smallest Script, Inverted Index
I've been doing the Perl Weekly Challenge (PWC) for 3 weeks now. So far there's been unique challenges that made me utilize different modules. I even submitted a solution using APIs which I haven't done in my work because I didn't have any reason to. (lol)
Task #1 - Smallest Script:
The tasks for this week's challenge (#24) are a bit confusing at first but I just did what was asked. The first task was to create the smallest script as described below:
Create a smallest script in terms of size that on execution doesn’t throw any error. The script doesn’t have to do anything special. You could even come up with smallest one-liner.
There is no problem to solve, so in my entry I just put a
The code did not throw any error even when I tried an empty script. I hope next week would be a golfing challenge at least. And that was Task #1, moving on to
Task #2 - Inverted Index:
I honestly haven't heard of the term. Good thing the task includes the Wiki description
Create a script to implement full text search functionality using Inverted Index. According to wikipedia:
In computer science, an inverted index (also referred to as a postings file or inverted file) is a database index storing a mapping from content, such as words or numbers, to its locations in a table, or in a document or a set of documents (named in contrast to a forward index, which maps from documents to content). The purpose of an inverted index is to allow fast full-text searches, at a cost of increased processing when a document is added to the database.
In my solution, I used hash to associate word with the files it was found. It follows the structure:
The hash would be later on used to print out the location/file(s) where the search keys can be found.
I used the
Text::Table::Tinymodule to print out a nice table. Output should look something like this: