http://www.perlmonks.org?node_id=1041132


in reply to Re: Too much recursion
in thread Too much recursion

In your code, it seems to me that you would wish to insert a next statement after the line with “number of hostnames” comment, so that the processing of that particular record ends at that point instead of falling-through.

The general structure of an awk program (this being one of the original inspirations for Perl) is instructive:   the awk language consists of regular-expression patterns followed by code-sections that are executed if a particular pattern is matched.   (Other special sections are executed at the beginning and at the end of the file.)   This encourages one to approach problems like these by first identifying each “type of line” that the file might contain ... building a regular expression for each ... then deciding what to do with each one.   In this example, there are at least two types:   “is a hostname line,” and “isn’t.”

Recursion isn’t needed to solve problems like these.   For dealing with very complicated inputs, the notion of a Finite-State Machine (FSM) can be useful.