in reply to Removing a Metacharacter from a filename
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 :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Removing a Metacharacter from a filename
by sputnik (Initiate) on Aug 26, 2009 at 22:57 UTC | |
by biohisham (Priest) on Aug 27, 2009 at 13:09 UTC |