Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

INPUT:- Warning: Found baddata Block list file: 231092

OUTPUT:- I need to capture the word between "found" and "block"

I tried the following (just snippet) but not working.Can someone help?
#get blocking type if ( $match =~ /Warning: Found/ ) { $block_type = (split /:\s*/, $match)[1]; chomp $block_type; next LINE;

Replies are listed 'Best First'.
Re: Regular expression help
by toolic (Bishop) on Oct 28, 2011 at 00:31 UTC
    One way to do it is to use capturing parentheses (perlre):
    use strict; use warnings; my $match = 'Warning: Found baddata Block list file: 231092'; if ( $match =~ /Warning: Found (\w+) Block/ ) { my $block_type = $1; print $block_type; }
Re: Regular expressionhelp
by mrstlee (Beadle) on Oct 28, 2011 at 12:06 UTC
    You can also do away with the explicit assignment from $1 & the chomp:
    #get blocking type my ($error,$block_type) = m /Found\s+(\S+)\s+.*:\s+(\d+)/x; ## Do something with the data if $error & $block_type ## exist do_something($error,$block_type) if defined $error; next LINE;