Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Parsing Text into Arrays..

by Gilimanjaro (Hermit)
on Jan 20, 2003 at 13:36 UTC ( [id://228340]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found