Let's look at my code:

Starting at the top, I assemble the command and parameter list in the @args array. The start command on Win32 takes the command to run as the first or second parameter, depending no the shell/OS. command.com takes it as the first parameter while cmd.exe takes it as the second parameter. So you can consider it as an old habit to put the file twice there. Typing help start in cmd.exe will tell you lots about other options.

my @args = ("start",$file,$file);

Next, I put all parameters that have spaces in them into double quotes. This is a very crude mechanism, because it doesn't pay attention to other characters that might confuse the shell, like ?,&,| or %. To prepend and append a double quote, I use alternative double quotes by using the qq quoting operator, see perlop or perldoc perlop, in case the link doesn't work.

for (@args) { # Apply smart-ish double quotes if (/ /) { $_ = qq{"$_"}; } };

Two alternative ways to achieve the same quoting would be :

$_ = '"' . $_ . '"'; # or $_ = "\"$_\"";

So I think you should see why I prefer $_ = qq{"$_"} over that.

The only thing that remains is to hand the parameter list to the shell:

system(@args) == 0 or warn "Couldn't launch '$file' : $!/$?/$^E";

In reply to Re^3: Perl Tk: opening a file in its original format by Corion
in thread Perl Tk: opening a file in its original format by FM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.