http://qs1969.pair.com?node_id=1177159


in reply to portability / system / elegance

Minimally more elegant (for some values of 'elegant'): use an alternative to the forward slash as a delimiter to change the path-separator in a code segment that ascertains the OS upon which the program is running (if ($^O eq 'MSWin32') { ... (adapted from below); } elsif ($^O eq 'linux') { ....

D:\_STM_work>perl -E "my $foo='/path/path/somepgm.exe'; if ($^O eq 'MS +Win32') {$foo =~ s?/?\/\/?g;} say $foo;" //path//path//somepgm.exe

Proofreading all the leaning toothpicks is a practice fraught with possibility of error; for elegance, stuff the separator changing into a sub which is called only when the script ascertains that the OS is some (recent) flavor of Windows.