in reply to Finding if files exist when names randomly have letters in both upper and lower cases

If your filesystem is not case sensitive, then -f should just work with the upper case names, if your filesystem is case sensitive, and the case from the database doesn't match what is on the filesystem, then you don't have a file with that name.

If your filesystem is case sensitive, and you still have to do this, you will have to break filename up into parts, search through each directory from the root, and look to see if any of the directories along the way match the one you are looking for (probably by converting the argument and the directories into the same case using uc() or lc().)

You are likely to get more help here though if you post some of the things you have tried, instead of just asking for someone to do it for you.


We're not surrounded, we're in a target-rich environment!
  • Comment on Re: Finding if files exist when names randomly have letters in both upper and lower cases
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Finding if files exist when names randomly have letters in both upper and lower cases
by jasonk (Parson) on Jun 22, 2005 at 14:27 UTC

    On second thought, this should work as well...

    use File::Glob qw(:globally :nocase); # instead of if(-f $file) { if(<$file>) {

    We're not surrounded, we're in a target-rich environment!
      use File::Glob qw(:globally :nocase); if(<$file>) {
      Thou Shalt Not Use Scalar Glob Unless Thou Understandest Thy Problems Perfectly.

      In layman's terms, your test will work "every other time" mysteriously.

      In real terms, what's happening is that a scalar glob context is established on the first hit, and then reused on the second hit, so you'll get your filename, then undef, then your filename, then undef, then your filename. Ick.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.


      update: And it was also pointed out to me in the CB that this is a readline() call, not a glob() call, which really wouldn't have worked.
Re^2: Finding if files exist when names randomly have letters in both upper and lower cases
by merrymonk (Hermit) on Jun 22, 2005 at 14:31 UTC
    Many thanks for your suggestions.
    I do appreciate your last comment and I would have done so
    had I thought any of my efforts were worthy of posting.