in reply to Is there any way to override "file test operator"?

Um, why would you even want to do this? You want to lie to your program about whether a file exists or not? Without some pretty specific and esoteric reasons, that just sounds silly

  • Comment on Re: Is there any way to override "file test operator"?

Replies are listed 'Best First'.
Re^2: Is there any way to override "file test operator"?
by Corion (Patriarch) on Aug 09, 2011 at 08:13 UTC

    One use I could see for this would be filenames that refer to a virtual file system. For example -f 'smb://server/share/file.name' or -r 'ssh:user@host:some/file' could be resource tests that make sense if you want to provide a different syntax than just local filenames.

Re^2: Is there any way to override "file test operator"?
by perlancar (Hermit) on Jan 31, 2018 at 11:40 UTC
    Another use-case is for testing, e.g. I have a test script that detects whether bash exists using -x "/bin/bash". I'd like to be able to simulate the absence of bash by returning false to that expression even though /bin/bash is actually on my filesystem.
Re^2: Is there any way to override "file test operator"?
by obfuscated (Initiate) on Mar 17, 2018 at 17:48 UTC
    Another use case is implementing support for symlinks on Windows. See Win32::Links for a situation where someone has taken the effort to do so, and could use a means of supporting -l to make it seamless.