in reply to Searching for a string within an array using regex
Thank you for your responses. I just realized that I actually offered an incorrect example. Let me share some actual code so you can see what I am working with and it will make more sense.
I read in lines from a file. The file contains one URL per line each starting with "/". For instance, "/help.html" or "/index.html" or "/help.html?ri=all". Each line gets stored into an array @line_entry.
Once all lines have been parsed into @line_entry, I iterate through $line_entry[$i]. At each iteration I do the following:
given ($line_entry[$i]) { when ($_ ~~ @INDEX_PAGE) { $INDEX_PAGE_COUNT++; } when ($_ =~ m/@HELP_PAGE/) { $HELP_PAGE_COUNT++; } }
In the case of @INDEX_PAGE, the reason I can get away with using that type of when condition is because the only possibly URLs that cane be parsed from the file are the only two that appear in the array @INDEX_PAGE = {"/", "/index.html"}. There is no regex required since there is no "/index.html?something". It is guaranteed to either be "/" or "/index.html".
However, array @HELP_PAGE = {"/help.html"} is defined as such, but the entries that can be found in the URL file may be "/help.html", but they could also be "/help.html?sometexthere". So I am trying to find the proper means to see if an element in an array is a subset of the string I'm currently examining, and not the other way around as I suggest in my initial post.
Thus, if the string currently being analyzed is ANYTHING that begins with "/help.html" (the element in the @HELP_PAGE array), it should resolve true.
Thank you again for your continued assistance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Searching for a string within an array using regex
by Anonymous Monk on Aug 14, 2014 at 18:02 UTC | |
by Anonymous Monk on Aug 14, 2014 at 18:14 UTC |