Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Using Map and RegEx for data extraction by jonadab
in thread Using Map and RegEx for data extraction by ajose

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-19 02:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found