it would be good if someone could explain how the follwing two Perl lines work since I do not understand them.
my ( $extention, $type ) = split '=', `assoc $arg_item 2>nul`; my( undef, $cmd ) = split '=', `ftype $type 2>nul`;

Essentially both lines do the same thing for the two commands. Breaking those lines down

  1. `cmd $arg 2>nul`

    Where cmd is either assoc or ftype; $arg is $arg_item or $type; and the 2>nul is command shell (cmd.exe) redirect of stderr to the nul device.

    The backticks (``) execute the command given passing the argument ($arg_item or $type respectively), and retrieve the output from those commands, whilst discarding any error messages produced.

    The output from both commands is in a similar format:

    c:\test>assoc .pl .pl=Perl c:\test>ftype Perl Perl="c:\perl\bin\perl.exe" -sw "%1" %*

    Ie. something=this other thing and the bit you want in both cases is the bit after the = sign.

  2. split '=', `...`; so the output of the command is past directly to split which splits the output into two pieces either side of the = and discard the =.
  3. my( $var1, $var2 ) = ... assigns names to those two pieces.

    Except that we don't really need the first part as that is just the same as the argument we gave the command. So in one case I chose not to name that part:

    my( undef, $cmd ) = split '=', `ftype $type 2>nul`;

    The undef there simply says that I don't really need to name the first part, so it is effectively discarded.

    Equally, the first line could also do the same thing and become:

    my ( undef, $type ) = split '=', `assoc $arg_item 2>nul`;

    Since we never make use of the variable I named $extension.

Well done for asking. I hope my explanation clarifies things?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^5: Getting File Types data by BrowserUk
in thread Getting File Types data by merrymonk

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.