From balaji.ramasubramanian at gmail.com Fri Feb 8 21:37:29 2019 From: balaji.ramasubramanian at gmail.com (Balaji) Date: Fri, 8 Feb 2019 21:37:29 -0800 Subject: [sf-perl] A basic text parser Message-ID: Hi all, I've been writing Perl for several years and I've always wondered that while text parsing is the most common thing done by all Perl programmers, why is there no lean and clean way to do it. Every time one has to write code like this: open FH, 'filename'; while () { if (m//) { ## Some condition } elsif(m//) { ## Another condition } else { ## More } } close FH; This is unfortunate. So I thought I'd make it a little simpler. I've posted a CPAN package named Text::Parser . It is a generic parser and you can very easily extend it to parse your own text formats by making a derived class, overriding just one method. If you do so, your main code could look this lean and mean: use MyComplexTextFormatParser; my $parser = MyComplexTextFormatParser->new(); $parser->read('filename.complex_format'); my (@records) = $parser->get_records(); Try it out and feel free to give feedback or file issues on the GitHub repository page. Thanks, Balaji -------------- next part -------------- An HTML attachment was scrubbed... URL: