you're actually replacing every none word character with an underscore. hence your filename "cos.NEW&OLD.0826.12345" would become "cos_NEW_OLD_0826_12345" which is obviously cumbersome to write, just in case. If you want everything remain the way it is, just escape the metacharacter itself.$script=~s/(\W)/_/g;
my $script = "cos.NEW&OLD.0826.12345"; $script=~s/\&/_/; print "$script"; #outputs "cos.NEW_OLD.0826.12345"
NOTE:Regular expression are not as consternating as they may seem!, invest the time at learning them effectively and you would see it coming your way easier than the head-whirlpool I used to suffer from when I did not know nothing about regexes, Now at least I can analyse and correlate them better. See it for yourself :)
In reply to Re: Removing a Metacharacter from a filename
by biohisham
in thread Removing a Metacharacter from a filename
by sputnik
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |