Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Using Map and RegEx for data extraction

by jonadab (Parson)
on Oct 14, 2014 at 10:42 UTC ( #1103704=note: print w/replies, xml ) Need Help??


in reply to Using Map and RegEx for data extraction

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1103704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2019-12-15 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?