in reply to String parameter parsing

Well, you're using the same regular expression three times, which is a good sign that you're making something harder than it needs to be. In particular, you don't need to remove the matched string at the end of the loop, because m//g will find the next occurence anyway.
while ($content =~ m/<\?Function\(([^\)]*)\)\?>/g) { my $params = $1; my @params = $params =~ m/"([^"]*)"/g; my $line = some_param_stuff(@params); }
(tested)

The regex I use to match the individual parameters assumes that there will be no escaped quotes within a parameter. (e.g. "my \"tricky\" parameter".)

Replies are listed 'Best First'.
Re: Re: String parameter parsing
by Beatnik (Parson) on Jan 19, 2001 at 03:19 UTC
    I don't want the <?Function("foo","bar")?> in $content after the processing. It should be replaced by the output from some_param_stuff(@params);. So I think I need s///. I don't really check for escaped \" either (altho I'm sure MRE mentions it somewhere).

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
      Ah, sorry, I overlooked that bit. In that case, you could just put the substitution back in at the end of my loop.

      Alternatively, the whole thing could be rewritten as a single substitution, with the /e modifier so the replacement will be eval'ed:

      $content =~ s/<\?Function\(([^\)]*)\)\?>/ my $params = $1; my @params = $params =~ m,"([^"]*)",g; some_param_stuff(@params); /ge;
        Muchos kudos :) I'll benchmark it :)

        Greetz
        Beatnik
        ... Quidquid perl dictum sit, altum viditur.