On 6/22/08, Pad <[EMAIL PROTECTED]> wrote: > Need your help again! > > I have a file that contains several _begin and _end classes with > _begin is that start of the block and _end being the end of block. > Sometimes we miss either _begin or _end. I am trying to write a > script that find every _begin should contain _end. If for reasons > _end is missing, it should error out. Likewise, if you have _end, you > should expect to have _begin in the previous lines. Can you help me > how to check this condition in my script? > > thanks > pad
More detail about the format would help. Assuming the expected format is something like: _begin CLASS_A ... _end CLASS_A ... _begin CLASS_B ... _end CLASS_B == CODE == #!/usr/bin/perl use strict; use warnings; my $in_class; while ( <> ) { if ( /^_begin (.*)$/ ) { if ( defined $in_class ) { print "Err. Found begin $1 while in class $in_class\n"; } $in_class = $1; } elsif ( /^_end (.*)$/ ) { if ( not defined $in_class ) { print "Err. End class $1 found without a begin.\n"; } $in_class = undef; } } == CODE == You can deal with nested classes using an array instead of a scalar $in_class. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/