Source-code compatibility: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 8:
It can be programmatically tricky to determine whether one is executing atop a Windows or UNIX environment. A simple-minded trick can often be resorted to, however. It is exemplified by the following Perl expression:
 
    '''-d "C:" && ! -d "./C:"'''
 
This expression determines whether a directory called C: exists and, moreover, verifies whether some wag deliberately created a subdirectory called "C:" within the current directory for the sole purpose of defeating the check. Since, of course, one occasionally encounters a Windows system that does not feature a C: drive, the expression can be generalized thus:
 
    '''join "", map { -d $_ && ! -d "./$_" } map { chr( $_ } . ':' ) ord( 'A' ) .. ord( 'Z' )'''
 
which actually applies the preceding logical test to the complete set A: through Z: of possible drives. Each test that succeeds returns a "1" while each that fails returns the empty string. Thus, if one or more of the drives exists, the return value will be a nonzero integer.