=Ronald J Kimball wrote:
> On Mon, Jul 09, 2001 at 05:18:08PM -0400, Morbus Iff wrote:
> > >if ($fileName =~ /\W+/) {
> >
> > Use:
> >
> > if ($fileName =~ /[\W+\.]/) {
>
> \W already includes period... I think you meant:
>
> if ($fileName =~ /[^\w\.]/) {
> # bad, bad filename!
> }
>
> Reject the filename if there's any character that's not a word character or
> a period.
>
> Ronald
This is a way to test what characters
belong to the sets \w and \W, respectively:
=cut
for (32..255) { push @char, chr($_) }
$_ = join "", @char;
print "\n\"word characters\" : ", join "", /[\w]/g;
print "\nNon-\"word characters\": ", join "", /\W/g, "\n";
=So this might be a better test for legal file names:
!m,[^\w_.~-],
And here you can test it with file names:
=cut
for (split "\n", "File1
File2.dat
File 3.exe
File4.dat.lalala
File_5
File~6~~~
File-7
File/7") {
printf "%-18s %s %s $s", "\n$_", " is", (!m,[^\w_.~-],?"":" not") . " a valid file
name." }
print "\n
Note:
1. within [ ] the characters . + do not need a \ .
2. What is a valid file name depends very much on the system you run.
These are valid file names in MacOS:
1 2 3
äöüÄÖÜ
%&%
^^^
+++***
and even one simple blank can denote a filename.
For (Li|U)n.x this test will not miss digits, letters, period, tilde, hyphen and
underscore:
!m,[^\w.~-],
Also Blank seems to be valid in Linux.
Greetings, Detlef"