Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Convert Tcl Keyed List to Perl

by LanX (Saint)
on May 22, 2013 at 16:16 UTC ( [id://1034782]=note: print w/replies, xml ) Need Help??


in reply to Convert Tcl Keyed List to Perl

Wow, seems like John Ousterhout really loved LISP

I was so kind to format your data with emacs

$kl_string=<<__KL__ { {Register { {CumulativeActive(calls)(In) 0} {CumulativeSuccessfullyEstablished(calls)(In) 0} {CumulativeSuccessfullyCompleted(calls)(In) 0} {CumulativeUnsuccessful(calls)(In) 0} } } } { { {Make Cal l} { {CumulativeActive(calls)(In) 0} {CumulativeSuccessfullyEstablished(calls)(In) 0} {CumulativeSuccessfullyCompleted(calls)(In) 0} {CumulativeUnsuccessful(calls)(In) 0} } } } { {Initiating { {CumulativeA ctive(calls)(In) 0} {CumulativeSuccessfullyEstablished(calls)(In) 0} {CumulativeSuccessfullyCompleted(calls)(In) 0} {CumulativeUnsuccessful(calls)(In) 0} } } } { {Summary { {CumulativeActive(calls)(In) 0} {CumulativeSuccessfullyEstablished(calls)(In) 0} {CumulativeSuccessfullyCompleted(calls)(In) 0} {CumulativeUnsuccessful(calls)(In) 0} } } } __KL__

and as it turns out it's a mixture of nested lists and keyed lists.¹

What's worse, I can't easily see a way to automatically distinguish between the two ...

(OK it's more than a decade that I used TCL for the last time.)

So w/o deeper information of the schema I'd rather recommend to try to find a JSON interface for TCL.

Cheers Rolf

( addicted to the Perl Programming Language)

¹) I suppose you want a nested data structure with Perl arrays and hashes

Replies are listed 'Best First'.
Re^2: Convert Tcl Keyed List to Perl
by LanX (Saint) on May 22, 2013 at 16:56 UTC
    this is a hack, no warranty whatsoever!

    $tcl_data =~ s/([^{}\s]+)/'$1',/g; # quote words + comma $tcl_data =~ s/{/[/g; # start list $tcl_data =~ s/}/],/g; # end list + comma #print $tcl_data; my @perl_arr = eval($tcl_data); # interpret as Array of AoAoA... use Data::Dump 'pp'; pp @perl_arr;

    thats the output

    ( [ [ "Register", [ ["CumulativeActive(calls)(In)", 0], ["CumulativeSuccessfullyEstablished(calls)(In)", 0], ["CumulativeSuccessfullyCompleted(calls)(In)", 0], ["CumulativeUnsuccessful(calls)(In)", 0], ], ], ], [ [ ["Make", "Cal", "l"], [ ["CumulativeActive(calls)(In)", 0], ["CumulativeSuccessfullyEstablished(calls)(In)", 0], ["CumulativeSuccessfullyCompleted(calls)(In)", 0], ["CumulativeUnsuccessful(calls)(In)", 0], ], ], ], [ [ "Initiating", [ ["CumulativeActive(calls)(In)", 0], ["CumulativeSuccessfullyEstablished(calls)(In)", 0], ["CumulativeSuccessfullyCompleted(calls)(In)", 0], ["CumulativeUnsuccessful(calls)(In)", 0], ], ], ], [ [ "Summary", [ ["CumulativeActive(calls)(In)", 0], ["CumulativeSuccessfullyEstablished(calls)(In)", 0], ["CumulativeSuccessfullyCompleted(calls)(In)", 0], ["CumulativeUnsuccessful(calls)(In)", 0], ], ], ], )

    you might wanna dig in and try to identify "arrays of two element arrays where the first element is a scalar" ( the "definition" of keyed lists), to convert them into hashes in the next step.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^2: Convert Tcl Keyed List to Perl
by jaredor (Priest) on May 24, 2013 at 02:30 UTC

    According to Abelson, Greenspun and Sandon, Ousterhout's love was a touch impure & practical. Per the slightly rueful historical assessment at the end of their Introduction to Tcl for Web Nerds:

    Lisp Without a Brain

    If in reading this introduction, you've come to realize that "Hey, Tcl is just like Lisp, but without a brain, and with syntax on steroids", you might wonder why Lisp isn't a more popular scripting language than Tcl. Lisp hasn't been a complete failure, by the way; it is used as an extension language by users of some popular programs, notably AutoCAD. But Tcl has been much more successful. It has been compiled into hundreds of larger programs, including AOLserver, which is why we wrote this book.

    I wonder what "Perl Without a Brain" would be?

      > I wonder what "Perl Without a Brain" would be?

      LOL ... brilliant analogy! xD

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 05:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found