Pad wrote: > > 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?
It is hard to understand your explanation. As long as '_begin' and '_end' appear at the start of the line in the input file you can write something like the program below. If this doesn't help you then please show us some of your actual data. HTH, Rob use strict; use warnings; my $nest = 0; while (<>) { if (/^_begin/) { die "Unexpected BEGIN found" if $nest; $nest++; } elsif (/^_end/) { die "Unexpected END found" unless $nest; $nest--; } } if ($nest) { die "Missing ", $nest > 0 ? 'END' : 'BEGIN', " marker" } print "File has balanced markers\n"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/