I'm developing a script that makes use of the -e
flag, as in
unless (-e $fileName)
{
...
}
This works fine on OS X. Or, rather, it doesn't work correctly. I want it to be case-sensitive. The script is also run on a Linux machine, and the -e
check fails--rightly!--because of case sensitivity.
I tried to do an alternate path with open <FILEHANDLE, '$fileName')
, but it seems that that, too, is case insensitive.
Edit: Thanks to everyone who answered below. I know HFS+ is case-insensitive, but I thought I could "force" it somehow. I did end up forcing a check by doing something like:
opendir my($dh), $dirName or die "Couldn't open dir '$dirName'";
my @refFiles = readdir $dh;
closedir $dh;
foreach $refFile (@refFiles)
{
if ($refFile eq $refFileName)
{
$found = 1;
}
}
The famous mantra: "It's not pretty, but it works."
The lack of case sensitivity is due to the filesystem you are using (HFS+), not the Perl functions -e
and open
, nor the underlying stat(2) and open(2) system calls.
The HFS+ filesystem is not case sensitive by default; however, you may elect to create a case-sensitive HFS+ volume when initializing a new filesystem (using Disk Utility, diskutil, or *newfs_hfs*, etc.): just select the “Case-sensitive” version.
I have seen reports of (badly written) programs malfunctioning when run from a case-sensitive boot volume, so I would advise you to use a separate volume for your case-sensitive work. For example, create a disk image (i.e. “sparse disk bundle image”) with a “Mac OS Extended (Case-sensitive, Journaled)” filesystem and mount it when you need to do your case-sensitive work (e.g. open ~/case-sensitive.sparsebundle
, then cd /Volumes/Case-sensitive/foobar
to do your case-sensitive work from there).