Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Parsing Challenge

by Masem (Monsignor)
on May 24, 2001 at 22:44 UTC ( [id://83062]=note: print w/replies, xml ) Need Help??


in reply to Parsing Challenge

my @off_pairs = split '=', $input; my %hash; my $lastkey = $off_pairs[0]; foreach ( 1 .. @off_pairs - 2 ) { my @array = split ' ', $off_pairs[ $_ ]; my $newlastkey = pop @array; $hash{ $lastkey } = join ' ', @array; $lastkey = $newlastkey; } $hash{ $lastkey } = $off_pairs[-1];

Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
(tye)Re: Parsing Challenge
by tye (Sage) on May 24, 2001 at 22:58 UTC

    Yeah, that is more what I was thinking. Here is a similar method:

    my $key; for( split /(?<==)/, $input ) { # Split after each "=" s#(^|\s+)(\S+)=$##; # Remove trailing key if( defined $key ) { # Not first time thru: $hash{$key}= $_; } $key= $2; # Note next key to use. }

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found