Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found