Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: case insensitive file operations

by wog (Curate)
on Sep 19, 2001 at 23:38 UTC ( [id://113455]=note: print w/replies, xml ) Need Help??


in reply to case insensitive file operations

There is no cleaner easy way. In general, the cleanest solution is to change your perl program to deal with case sensitive file systems correctly, and just generally program portably. See also perlport.

Note that a -f does not test for file a exsitence alone -- it also checks if it's a "regular" file (not a directory, device, pipe, etc.) (If you want to test for file exsitence, alone, that would be -e.) Also, note that your regex does not match the way you think it does.

  1. it will match parts of a string. So a file called "test1" will be said to exsit by it if a file called "test10" exsits,
  2. metacharacters are not escaped, so "." will not mean the "." character itself but any character (except newline) when matching filenames.
You could fix these problems with using a regex, but your are probably better off using either lc or uc and eq, e.g.: my($exsits) = grep { lc($file) eq lc($_) } readdir DIR

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://113455]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found