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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: portability / system / elegance
by atcroft (Abbot) on Dec 04, 2016 at 15:59 UTC |
In Section
Seekers of Perl Wisdom