Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Perl Parsing Based on Supplied Precedence

by grizzley (Chaplain)
on Nov 07, 2012 at 10:01 UTC ( #1002649=note: print w/ replies, xml ) Need Help??


in reply to Perl Parsing Based on Supplied Precedence

You can simplify code a little bit by moving $node declaration to the inner loop (and I replaced condition $3 with match result):

sub parse { my ($regex,$input)=@_; for(@$regex) { if($input=~m/(.+)($_)(.+)/) { my ($before,$op,$after,$node)=($1,$2,$3); $node->{$op}=[parse($regex,$before), parse($regex,$after)] +; return $node; } } return $input; }
and optimize the code by moving $input=~s/\s//g outside parse sub. It is enough to do this once in while loop after reading input data.


Comment on Re: Perl Parsing Based on Supplied Precedence
Select or Download Code
Re^2: Perl Parsing Based on Supplied Precedence
by protist (Monk) on Nov 07, 2012 at 11:41 UTC

    That is very slick. I was worried about checking for a match then doing a match with groups being two regex operations, but for some reason didn't think to do both at once as you did.

    +1

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002649]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-07-23 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (137 votes), past polls