Hmm... let's see... If I were going to golf this down... I think the first thing I'd want to do would be to get rid of a bunch of unnecessary temporary variables and just let the results flow, using the return value from one thing as the argument for the next (i.e., functional paradigm). In this case, this would probably also mean turning the foreach loop into a map. Perhaps something like this (untested, because I'm not on MS Windows here):
print map {
my @list = split /,/, $_;
map {s/"//g} @list;
$list[1];
} `tasklist /FI "IMAGENAME eq perl.exe" /NH /FO CSV`;
Inside the map, you've already got a map, but you're using it like another foreach loop, which is weird. But anyway, I'd do basically the same thing inside of there. For example, we can do without the @list variable.
print map {
(map {s/"//g} split /,/, $_)[1]
} `tasklist /FI "IMAGENAME eq perl.exe" /NH /FO CSV`;
That's all purely mechanical, changes that can be made more or less automatically, without thinking very hard about what the code's doing. If I wanted to go much further, I'd have to slow down a bit probably and actually know what's going on, maybe get a Microsoft Windows system and look at the output of tasklist so I can see what's being parsed, etc.
-
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.