Assign each line to the $_ variable and try this to get the number of instances of < and >
The match operator works on $_ by default. If you match on < or > globally and assign it to an array like so: @rights = m/\</g; @lefts = m/\>/g; You are left with arrays that contain all the matches. Now all you need to do is count the number of elements in each array like so: $number_of_rights = $#rights; $number_of_lefts = $#lefts; Then compare them: if ($number_of_rights != $number_of_lefts) { ## scream here!! } -----Original Message----- From: S.A. Birl [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 27, 2004 3:23 PM To: [EMAIL PROTECTED] Subject: Recursively counting a matching pattern on a single line. Given a bookmark: <DT><A HREF="http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html" ADD_DATE="897592292" LAST_VISIT="982769648" LAST_MODIFIED="982769648" ID="rdf:#$rsy5Z">PERL FAQ</A> Wondering if it's possible to have 2 counters that would keep track of the number of < and > encountered. Im looking to see if there's a balance of < and >, and scream as soon as there isnt a balance. So given the above bookmark, I know that there's 3 < and 3 > and the pattern is basically <><><> and not <<>> or >><, etc. Thanks Birl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>