File Name Checking

R

Rich Bogle

Does anyone have a good module or clean method for making sure file names do
not have special charactes / illegal characters in them before attempting to
save the file.

I have a perl script that archives data based upon information in a text
file in each directory. The archive location is derived from that location
and I need to make sure there are no illegal / special characters in the
file name before creating it.

Thanks

Rich
 
R

Rich Bogle

Just thought that I should mention the email goes straight to a junk account
so all replies should be posted in the group.
Thanks.
 
J

Jim Gibson

Rich Bogle said:
Does anyone have a good module or clean method for making sure file names do
not have special charactes / illegal characters in them before attempting to
save the file.

I have a perl script that archives data based upon information in a text
file in each directory. The archive location is derived from that location
and I need to make sure there are no illegal / special characters in the
file name before creating it.

Thanks

Rich

Use the tr operator to replace every character except those you wish to
keep. For example, if you only want the characters (a-zA-Z0-9_-.), use:

$filename =~ tr/a-zA-Z0-9_-.//cd;

For more info, enter "perldoc perlop" and search for 'Transliterates'.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top