Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: portability / system / elegance

by atcroft (Abbot)
on Dec 04, 2016 at 15:59 UTC ( [id://1177162]=note: print w/replies, xml ) Need Help??


in reply to Re: portability / system / elegance
in thread portability / system / elegance

Would not the more "elegant" solution be to use a module that is designed for this purpose, File::Spec? From the documentation for the module, File::Spec requires an appropriate module (File::Spec::Cygwin, File::Spec::Unix, and File::Spec::Win32, among others), which alters such functions as catfile in an appropriate manner. Taking from ww's example (and setting the path value in a sub) using this code:

perl -MFile::Spec -le 'sub tshark_path { my @filename = qw( / usr bin +tshark ); if ( $^O eq q{MSWin32} ) { @filename = ( q{c:}, q{Program F +iles}, q{Wireshark}, q{tshark.exe} ); } return @filename; } my @file += tshark_path(); print File::Spec->catfile( @file );'

gives the following results when executed on Cygwin (under Win10), Win10, and linux:

# Result under Cygwin /usr/bin/tshark # Result under Win10 (Powershell) C:\Program Files\Wireshark\tshark.exe # Result from linux /usr/bin/tshark

Hope that helps.

Log In?
Username:
Password:

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

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

    No recent polls found