in reply to Using Map and RegEx for data extraction
The above code works just fine. But I wonder there is any shorthand method to extract the same with a single line
Sure, its called a subroutine
print join ' ', win32perlProcPids(), "\n"; sub win32perlProcPids { my @tasks = `tasklist /FI "IMAGENAME eq perl.exe" /NH /FO CSV`; my @pids; foreach my $task (@tasks) { my @list = split /,/, $task; s/"//g for @list; push @pids, $list[1]; } return @pids; }
|
|---|