There's more than one way to do things | |
PerlMonks |
Re: Replacing Whitespace with Underscoreby jimpudar (Pilgrim) |
on Apr 09, 2018 at 16:24 UTC ( [id://1212598]=note: print w/replies, xml ) | Need Help?? |
You should turn on 'use strict' and 'use warnings', this will help lead you to a better solution. It seems your main problem might be that you are confusing the space character ' ' with the whitespace character class. In a regex, '\s' matches not only the space character, but ANY whitespace character. See Whitespace. Your substitutions like 's/\[/\s/' will fail because '\s' is only recognized as whitespace in a regex:
Also, your regex for substituting whitespace with underscore will only match a whitespace character followed by a space character. I don't think this is quite what you meant.
Best, Jim
In Section
Seekers of Perl Wisdom
|
|