We don't bite newbies here... much | |
PerlMonks |
Simple way to skip spaces and # commentsby leszekdubiel (Scribe) |
on Jul 31, 2020 at 10:43 UTC ( [id://11120118]=perlquestion: print w/replies, xml ) | Need Help?? |
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?
Back to
Seekers of Perl Wisdom
|
|