in reply to Re: recursive parsing techniques
in thread recursive parsing techniques
For example, a one-liner which (eventually) exhausts the memory available to the Perl process:
rob@development:/home/rob/workspace$ perl -e 'sub a { &a }; a' Out of memory!
This can be prevented by the incorporation of a maximum depth for subroutine recursion such as follows:
sub parsevcard { my ($inputstr, $inputpos, $depth) = @_; if ($depth > $max_depth) { # Recursion beyond allowable depth error handling here } . . $currentcard->{AGENT} = parsevcard($inputstr, $pos, ++$depth); }
Depending upon the recursive problem at hand, this error trapping can be performed by way of examination of the output data structure alone, for example, the number of elements within an output array, rather than by a separate counter per se.
perl -le "print+unpack'N',pack'B32','00000000000000000000001010011110'"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: recursive parsing techniques
by exussum0 (Vicar) on Dec 29, 2003 at 16:30 UTC |