Keenan, Greg John (Greg)** CTR ** wrote:
> Hi,

Hello,

> Need some help with a regex please.
> 
> I need to search a file for every instance of a string that ends with %.
> Think output from the df command.  I need the 1, 2 or 3 digits before the %
> passed into the array.
> 
> Code:
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> my $outfile2 = "XXX.dat";
> open(DATA2, "< $outfile2") || die "Can't open $outfile2: $!\n";
> while(<DATA2>) {
>   my @oput2 = /\b([0-9]+)%/;
>   print "XXX @oput2 XXX\n";
> }
> close(DATA2);
> 
> It is kind of working but I pick up stuff I don't want e.g:
> 
> Input data(XXX.dat):
> head
> 123 123 111% 123
> 456 22% 456 456 456
> 789
> tail
> 
> Output data:
> XXX  XXX
> XXX 111 XXX
> XXX 22 XXX
> XXX  XXX
> XXX  XXX
> 
> How do I tell it not to process every line in the file, just the lines that
> contain the relevant string?

while(<DATA2>) {
  my @oput2 = /(\d+)%/ or next;
  print "XXX @oput2 XXX\n";
}



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to