leszekdubiel has asked for the wisdom of the Perl Monks concerning the following question:
I parse string using /gc and \G regexes. Current solution for skipping white characters and comments starting from # to the end of line is:
$$a =~ /\G(?=(\s|#))(?:\s++|#.*+)++/gc;Look ahead ?= assertion is necessary, because zero-length matches cause problems. That solution unfortunatelly gives error:
Complex regular subexpression recursion limit (32766) exceededI have changes to such one:
while ($$a =~ /\G(?:\s++|#.*+)/gc) {};but this is not elegant. I have changed "+" to "*" after "\s" and this also solves the problem, but I don't know why...
$$a =~ /\G(?=(\s|#))(?:\s*+|#.*+)++/gc;Questions: (1) what is the better solution to strip white chars and commments (2) why * instead of + solves the problem?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Simple way to skip spaces and # comments
by ikegami (Patriarch) on Jul 31, 2020 at 14:18 UTC | |
by leszekdubiel (Scribe) on Jul 31, 2020 at 14:36 UTC | |
by ikegami (Patriarch) on Jul 31, 2020 at 14:42 UTC | |
Re: Simple way to skip spaces and # comments
by perlfan (Vicar) on Jul 31, 2020 at 11:28 UTC | |
by leszekdubiel (Scribe) on Jul 31, 2020 at 13:56 UTC | |
by perlfan (Vicar) on Jul 31, 2020 at 16:24 UTC |
Back to
Seekers of Perl Wisdom