http://qs1969.pair.com?node_id=1103704


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.