Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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
Replies are listed 'Best First'.
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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-11-28 19:04 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (743 votes), past polls