#!/usr/bin/perl -wl
use strict;
# have to search a little differently for nested tags
# making sure that an ending tag belonging to
# a nested opening tag is not processed as the ending
# tag for the current opening tag.
# In case i sounded awkward, here's a little diagram:
#
# <--- this tag
# <--- nested open tag
# <--- end tag for the nested open tag
# <--- end tag for this tag (the one that has
# to be picked up)
#
# Actual example:
my @chunks = ("\cJ\cI ",
"\cJ\cI\cI ",
"\cJ\cI\cI ",
"\cJ\cI ",
"\cJ\cI\cI \cJ\cI BOOL is true!\cJ",
"\cJ\cIBOOL is false!\cJ",
'');
my $opening_tag = qr/\ 0)
? ($nested--)
: (0)
)
: (
($chunks[$found_i] =~ m/^$opening_tag/)
? (++$nested)
: (1)
)
)
&&
( $found_i < @chunks )
)
{
print "F: $found_i ",
"N: $nested ",
"C: $chunks[$found_i]",
;
}
__END__
F:\dev\vladb>perl nestag.pl
F: 1 N: 1 C:
F: 2 N: 2 C:
F: 3 N: 1 C:
F: 4 N: 0 C:
BOOL is true!
F: 5 N: 0 C:
BOOL is false!