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: 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: In that case, the list that you get, looks like: 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: 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
|
|