Welcome to the Monastery | |
PerlMonks |
Re: portability / system / elegance (updated)by haukex (Archbishop) |
on Dec 04, 2016 at 15:58 UTC ( [id://1177161]=note: print w/replies, xml ) | Need Help?? |
Hi skendric, In my experience, the best thing is to use modules to help you. A quick glance at the source of File::Which shows that it uses File::Spec internally, so the filenames that which is returning should already be in the native format. You can test this via use Data::Dumper; $Data::Dumper::Useqq=1; print Dumper($tshark_binary); (although keep in mind that the output will be in Perl's notation, so e.g. $VAR1 = "C:\\Foo\\Bar.txt" means that the string is actually C:\Foo\Bar.txt). As for calling external commands, I would not recommend the system(STRING) form, but instead the system(LIST) form (Update: that is, system called with more than one argument, or even better, the system PROGRAM LIST form), or even better, a module such as IPC::Run3, which allows you to dodge most shell quoting and escaping issues (on Linux, it can avoid the shell completely, and on Windows, it automatically uses Win32::ShellQuote).
Although, if tshark is already in your $ENV{PATH}, why use which at all? Hope this helps,
In Section
Seekers of Perl Wisdom
|
|