Hi Monks!
I have a list of paths. There is a bug in the utility which reported those paths. The bug is that some of the special chars are being replaced with spaces but we don't know which.
The list of special chars:
my @special_chars = (":", ";", ",", "=", "-");
Given that list of paths and the array of special chars, I want to report all existing possible paths. Kind of brute-force on all the options. So, as I understand, the algorithm is to replace each space with one of the chars and check if that path exists. If so, report it.
If there was only one special char, I would just use one foreach loop on the chars and replace all the spaces in the path with the special char and check if the path exists using -e. But since there are multiple chars, I'm not sure how to do it. I don't want to have 5 different loops.
Some examples:
/a/b/c/d/e/fi:le /a/b/c/d/e/fi:l;e /a/b/c/d/e/f-i:l;e /a/b/c/d/e/f-i-:l;e /a/b/c/d/e/f:i-:l;e
In that case, the list that you get, looks like:
/a/b/c/d/e/fi le /a/b/c/d/e/fi l e /a/b/c/d/e/f i l e /a/b/c/d/e/f i l e
And the previous list is what you should build.
Note that there could be multiple spaces one by one and the special chars to fill them, could be different.
It feels like a question from "introduction to CS" but I can't seem to figure this one. How can it be done?

EDIT: Thanks all for the suggested implementations. I now understand that my current suggested algorithm to just fill and detect all the paths, does not work.
How can I use the system instead? For example, given a path with spaces, try to see if there is a matched path with some filled chars (does not have to be the special ones). If there are paths, then get only those paths that were filled with the special chars - should it be faster? How it can be done?
For example, for /a/b/c/d/e/f i l e it will find:
/a/b/c/d/e/f-i:l;e /a/b/c/d/e/fai:l;e /a/b/c/d/e/fai:lbe
Then, since only /a/b/c/d/e/f-i:l;e used the special chars, then it will be printed.

In reply to How to replace spaces with different chars? by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.