When I wrote my code, I didn't look closely at the way that these lines were generated and how the @array was built.
But to generate the @array, with this DATA, here is one way....
#!/usr/bin/perl -w use strict; my @data; foreach my $line (<DATA>) { # anchor match to the end of string with $ # anchor match to the beginning of string with ^ # ignore the K and spaces at the end (includes \n) # get the numbers and commas right before the K # get this stuff in front ($before) # but ignore any leading spaces in the line # a "greedy" match will not be so "greedy" that it # won't allow the last part of the regex to match # so it is not necessary to constrain the .+ match here my ($before, $mem) = ($line =~ /^\s*(.+)\s+([\d,]+)\s*K\s*$/); $mem =~ tr/,//d; #delete commas in like 2,787,204 push @data, "$mem $before\n"; #adds the \n back in } print @data; =prints: 1788180 disp+work.exe 3380 Console 0 2787204 sqlservr.exe 1768 Console 0 1078120 jlaunch.exe 4608 0 1830376 sqlservr.exe 1812 0 488716 disp+work.exe 4772 0 17 small_proc 9412 Console 0 =cut __DATA__ disp+work.exe 3380 Console 0 1,788,180 K sqlservr.exe 1768 Console 0 2,787,204 K jlaunch.exe 4608 0 1,078,120 K sqlservr.exe 1812 0 1,830,376 K disp+work.exe 4772 0 488,716 K small_proc 9412 Console 0 17 K
In reply to Re^2: transfer a array to a hash
by Marshall
in thread transfer a array to a hash
by BlackForrest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |