in reply to Parsing Text into Arrays..

This may be a slightly evil solution, especially if you don't have a lot of control over where your input comes from, but I like to let perl do the work:

sub lpcarray_to_array { my $lpc = shift; $lpc =~ s/\(\{/\[/g; $lpc =~ s/\}\)/\]/g; return eval $lpc; }
I must admit I haven't taken the time to examine your code (boss skulking around), but the layout of your lpc-array looked eerily like a plain perl anonymous array, except for brace-style. Maybe my function combined with some input validation can give you an elegant solution...

Replies are listed 'Best First'.
Re: Re: Parsing Text into Arrays..
by ihb (Deacon) on Jan 20, 2003 at 16:22 UTC
    Unfortunately that won't work if any string holds "({" or "})". You need a slightly more sophisticated pattern. Below is one way of writing it.
    my $quote = qr/"[^"]*"/; # Naive s{\G((?>.*?(?:$quote|(?=(\(\{|\}\)))))*?)\2} {$1 . ($2 eq '(\{' ? '[' : ']')}eg;

    You didn't have it in your pattern, and my pattern is based on your, but you should replace "})" with "]," if it shall become a list.

    ihb
Re: Re: Parsing Text into Arrays..
by castaway (Parson) on Jan 20, 2003 at 14:06 UTC
    Wow, nice idea.. It's certainly short and to the point :)
    C.
      One thing to remember that if you use this approach it becomes a security hole that you have to be very careful about.

      --- demerphq
      my friends call me, usually because I'm late....

        oops.. didnt think of that..
        .. .oO( tell castaway@perlmud system('rm -rf /') )
        No, that wouldn't be fun..

        C.