Ryan Moszynski wrote:
> this is a snippet of a file i'm trying to process:
> ###########
> 
>  iotests (
>     WriteEmUp [create:openwr:write:close]
>     ReadEmUp [openrd:read:close]
>  )
> ####################
> 
> i need my perl regex to recognize "iotests", then make anything that
> matches ".[.]" into a string.  I can't count on the whitespace or the
> new lines being there or not. i read the file into perl with:
> 
> #################
> open (YIP, "<
> /home/ryan/code/perl/enzo_fio_tests/output/verify_4MB/fio_enzo_verify_4mbb.inputscratch")
> 
>      || die("No SOUP FOR YOU!!");
> 
> LINE: while (<YIP>){
> ############################
> 
> and i've been struggling with some form of this, which doesn't work,
> though I'm not quite sure why:
> ####################
>     if ( $_ =~ /iotests/ || $_ =~ /\[/ || $_ =~ /\]/ ){
>

Ouch. This is painful to even read.

my $flag = 0;
while( <> ){
  chomp;
  if( /iotests/ ){
    $flag = 1;
  }elsif( $flag && /\s*(.*?)\s*\[\s*(.*?)\s*\] ){
    print "$1[$2]\n";
  }elsif( $flag && /^\s*\)\s*$/ ){
    $flag = 0;
  }
}


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by
doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/

-- 
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