http://www.perlmonks.org?node_id=59505

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently trying to shove together a script to back up all the writeups an Everything2 user has to files, each one named for the title of the node it comes from.

There is just one problem -- the set of legal characters for node titles is larger than the set of characters most operating systems will support in the filesystem. The perlport man page suggests dropping everything except alphanumerics and the period, but I would rather keep the title as close as possible to the original, perhaps even able to be translated back with the right incantations. I have thought about using the CGI library function escape(), but that would use the % sign for some things, and a question mark is still legal.

Is there some portable way to escape characters appropriately for a given filesystem? Failing that, what would an approximation that will cover the common operating systems in use look like? Ideally, I'd like to make it fairly foolproof in terms of not having to install new modules, but solutions featuring that are okay too.