BðP


Win32::StrictFileNames


How do I obey Newton's rule?
He said, ``If I have seen further than others,
it is because I've stood on the shoulders of giants.''
These days we stand on each other's feet!

Richard Hamming

Introduction

In Windows, the directories and files names are case-insensitive. That can be very boring.

Suppose that we run this very simple script on an OS with a case-sensitive file system:

 #!/usr/bin/perl -w
 use strict;
 use tk;     # <-- there is a typo here
 
 my $mw = MainWindow->new();
 MainLoop();
We obtain the error message:
 Can't locate tk.pm in @INC (@INC contains: ...etc
so it's easy to fix the typo.

But if you run the same script in Windows, you obtain a bunch of error messages:

 Subroutine Tk::optionAdd redefined at C:/perl/site/lib/Tk/Submethods.pm line 19.
 Subroutine Tk::optionGet redefined at C:/perl/site/lib/Tk/Submethods.pm line 19.
 Subroutine Tk::optionClear redefined at C:/perl/site/lib/Tk/Submethods.pm line 19.
 ... etc ...
 Subroutine Tk::configure redefined at C:/perl/site/lib/Tk.pm line 84.
 Subroutine Tk::cget redefined at C:/perl/site/lib/Tk.pm line 84.
 Undefined subroutine &main::MainLoop called at C:\tmp\ex.pl line 6.
...203 error messages unrelated with the typo! (Perl, internally, uses the file name 'tk' and not 'Tk' ...)

If we enable the strict file names checking with

 #!/usr/bin/perl -w
 use strict;
 use Win32::StrictFileNames;
 use tk;     # <-- there is a typo here

 my $mw = MainWindow->new();
 MainLoop();
we obtain the right error message:
 Can't locate tk.pm in @INC ...

Because it is not always obvious to find where the path is incorrect (especially if you are dislexic ;-), the 'warn' option exists.
For instance, if you run this script:

 #!/usr/bin/perl -w
 use strict;
 use Win32::StrictFileNames 'warn';
 use Tk;

 my $mw = MainWindow->new();
 my $img=$mw->Photo(-file => "$Tk::library/demos/images/Mickey.gif");
 $mw->Label(-image => $img)->pack;

 MainLoop();                       
you will get a warning message:
 Warning: case sensitive mismatch between
 File =C:\perl\site\lib\Tk\demos\images\Mickey.gif
 Long =C:\perl\site\lib\Tk\demos\images\mickey.gif
 Short=C:\perl\site\lib\Tk\demos\images\mickey.gif
   at C:/perl/site/lib/Tk/Image.pm line 21.
File is the file path to open, Long and Short are the paths retained by the system, for comparison (the file path is compared to short and long paths, segment by segment).
So, here, you see that the real file name is mikey.gif.

This module is still experimental. Only use it for debug purpose (to test the paths in a cgi script, for instance).

Back to Top

Download

Current version is 0.01

The module is in my ppm repository.
If you are using ActiveState's Perl distribution (Perl 5.6 or Perl 5.8), the easiest way to install this module is to use ppm. Enter (or cut & paste) this command in a DOS console:

    ppm install http://www.bribes.org/perl/ppm/Win32-StrictFileNames.ppd

The documentation, in html format, is at its usual location.

If you want, you can download the source file here: Win32-StrictFileNames-0.01.tar.gz
or from the CPAN
To install the module, read the README file.

Back to Top
:-)


BðP © 2003-2006 J-L Morel - Contact : jl_morel@bribes.org [Validation HTML 4.0!]