Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: How to find matching pairs

by I0 (Priest)
on Mar 12, 2002 at 09:47 UTC ( #151075=note: print w/replies, xml ) Need Help??

in reply to How to find matching pairs

$text = "A(B(2)+C(D())),\nTT(TT()+TT(TT()))"; $text = doFunc( "MAIN", $text ); # print "Example: $text\n"; sub doFunc{ my( $theFunc, $theParam ) = @_; # FIXME: greedy match fails with: 'TT(TT()+TT(TT()))' my $re; {local $^W=0; ($re=$theParam)=~s/((\()|(\))|.)/${[')']}[!$3]\Q$1\E$ +{['(']}[!$2]/gs; $re= join'|',map{quotemeta}eval{$theParam=~/$re/};} die $@ if $@=~/unmatched/; $theParam =~ s/([A-Z]+)\(($re)\)/&doFunc($1,$2)/geo; my $result = ""; if( $theFunc eq "MAIN" ) { $result = $theParam; } else { # dummy switch here for demonstration # this would be an elsif for each function $result = "func $theFunc returns <$theParam>"; } return $result; }
Update: Why does this dump core when the /o is removed?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://151075]
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....
[stevieb]: ++ atcroft

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2017-04-29 04:40 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.