in reply to Re^4: Getting File Types data
in thread Getting File Types data
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
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.
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?
|
|---|