in reply to translate arglist

Why not just use one hash, the key is the function name and the argument is an array consisting of search regex and replacement. Something like the following:
use constant SEARCH => 0; use constant REPLACE => 1; my %translate = ( funca => [ qr/funca\( ([^,]+) , ([^,]+) ,([^,]+) ,([^)]+) \)/x, '"func($1,$2,XXX,YYY,$4)"' ], funcb => [ qr/funcb\( ([^,]+) , ([^,]+) ,([^,]+) ,([^)]+) \)/x, '"func($1,$2,,,$4)"' ], ); while (<DATA>) { for my $key (keys %translate) { if (/$key/) { s/$translate{$key}->[SEARCH]/$translate{$key}->[REPLACE]/e +e; print; } } } __DATA__ funca(10,20,30,40) funcb(10,20,30,40)
Of course you might have to adjust the regexes a bit, taking care of whitespace, ... but I think you get the idea.

-- Hofmator

Replies are listed 'Best First'.
Re: Re: translate arglist
by denap (Initiate) on Feb 04, 2003 at 16:51 UTC
    How would I construct a regex that would also allow a parameter to the func (could be any parameter!) to also be a func with args... ugh. I found several cases where the arglist is not simple. i.e. funca(1,2,func35(A,B),3) in this case I need a regex that'll set $1->1, $2->2, $3->func35(A,B), $4->3.