in reply to Re^2: print data between with regexp...again
in thread print data between with regexp...again

Still can't replicate. I changed your system call to ps -o pcpu,vsz,stime,etime,pid,args -A|sort -nk1 (note the swapped arg list on sort) and had no trouble, but if the problem were your system call you'd have different behaviors. I assume line 34 corresponds to print $vals,"\n";. Do you see expected values if you comment out your lines 33 and 34 and insert print; (which will print the content of the special variable $_)? If I modify your given sample data to run in a DATA block and again use your loop unmodified, I get the output

7712 15:50:39 01:16 27661 7712 15:50:35 01:20 27501 7712 15:50:41 01:14 27739 7712 15:50:43 01:12 27815 7712 10:51:28 05:00:27 15822

Replies are listed 'Best First'.
Re^4: print data between with regexp...again
by Anonymous Monk on Nov 02, 2010 at 20:34 UTC
    I see what you mean. I changed the 1st if clause and my $vals, but now my output is spitting out the leading /.
    open (my $ps, "-|", "/usr/bin/ps -o pcpu,vsz,stime,etime,pid,args -A|s +ort -nk1") or die "ps not opened $!"; while (<$ps>) { next if $. == 1; next if /\/usr\/cachesys\/mgr -U/i; ### Skip interactive sessions +### #my @tmp = split if /cache/ig; if ( /(cache\s-s.*)/ig ) { #print $1,"\n"; my @tmp = split; my ($key) = split " ",$tmp[0]; #my ($vals)= $_ =~ /([^cache]*)/; my ($vals) = $_ =~ /\b\s|\d+\.\d+\s+\b(.*?)\b[\/usr|cache].*\b/; print $vals,"\n"; } #my @tmp1=@tmp[1,2,3,4]; #$psH{$key} = [@tmp1]; } #use Data::Dumper; __OUTPUT__ 712 13:50:17 02:41:32 11354 7712 03:31:27 13:00:22 27747 22048 00:48:04 15:43:45 12141 7712 16:12:40 19:09 211 7712 10:51:28 05:40:21 15822 7712 15:50:39 41:10 27623 / 7712 15:50:39 41:10 27614 / 7712 15:50:39 41:10 27622 / 7712 15:50:39 41:10 27615 / 7712 15:50:39 41:10 27626 / 7712 15:50:39 41:10 27618 / 7712 15:50:39 41:10 27625 / 7712 15:50:39 41:10 27621 / 9760 15:50:39 41:10 27627 / 9760 15:50:39 41:10 27613 /
    </code>