in reply to print data between with regexp...again

The warnings are being issued due to code you are not showing us. When crafting posts, please create small, complete programs that replicate your issue; see How do I post a question effectively?.

The code

#!/usr/bin/perl use strict; use warnings; while (<DATA>) { print /\b\s\d+\.\d+\b|\b\d+\.\d+\b(.*?)\bcache\b/; print "\n"; print /\b\s|\d+\.\d+\b(.*?)\bcache\b/; print "\n"; } __DATA__ 42.95 7712 15:20:05 08:30 23684 cache -s/usr/cachesys/mgr -cj -p +374 JOB^CCJOB 42.18 7712 03:31:27 11:57:08 27747 cache -s/usr/cachesys/mgr -cj -p +91 JOB^CCJOB

outputs

7712 15:20:05 08:30 23684 7712 15:20:05 08:30 23684 7712 03:31:27 11:57:08 27747 7712 03:31:27 11:57:08 27747

where I have not modified your regular expressions.

Replies are listed 'Best First'.
Re^2: print data between with regexp...again
by Anonymous Monk on Nov 02, 2010 at 19:52 UTC
    understood: here is my code.
    open (my $ps, "-|", "/usr/bin/ps -o pcpu,vsz,stime,etime,pid,args -A|s +ort -kn1") 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.*|\/usr\/cachesys.*)/ig ) { #print $1,"\n"; my @tmp = split; my ($key) = split " ",$tmp[0]; #my ($vals)= $_ =~ /([^cache]*)/; my ($vals) = $_ =~ /\b\s|\d+\.\d+\b(.*?)\bcache\b/; print $vals,"\n"; } #my @tmp1=@tmp[1,2,3,4]; #$psH{$key} = [@tmp1]; } close ($ps) __SAMPLE DATA__ 8.45 7712 15:50:37 01:18 27551 cache -s/usr/cachesys/mgr -cj -p2 +95 JOB^CCJOB 9.61 7712 15:50:39 01:16 27661 cache -s/usr/cachesys/mgr -cj -p +295 JOB^CCJOB 9.69 7712 15:50:35 01:20 27501 cache -s/usr/cachesys/mgr -cj -p +295 JOB^CCJOB 9.87 7712 15:50:41 01:14 27739 cache -s/usr/cachesys/mgr -cj -p +295 JOB^CCJOB 10.62 7712 15:50:43 01:12 27815 cache -s/usr/cachesys/mgr -cj -p +295 JOB^CCJOB 23.68 7712 10:51:28 05:00:27 15822 cache -s/usr/cachesys/mgr -cj -p +305 JOB^CCJOB
      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
        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>