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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|