This very short program turns perl data into lisp data. I used it at work to turn the Data::Dumper output of a program into lisp data. This is mostly because the lisp is easier on the eyes than Data::Dumper.
#!/usr/local/bin/perl use strict; no strict 'vars'; use warnings; use Scalar::Util 'reftype'; undef $/; my $s = eval <STDIN>; print $@ ? $@ : "(pp `".lisp( $s ).")\n"; sub lisp { # This is an utter, ugly hack. Please pretend you never saw it. my $thing = shift; my $type = reftype( $thing ); no warnings 'uninitialized'; if ( 'HASH' eq $type ) { # Returns an association list # ((KEY . VALUE) # (KEY . VALUE) # (KEY . VALUE)) return '('. join( '', map { "($_ . ".lisp($thing->{$_}).')'} s +ort keys %$thing ) .')'; } elsif ( 'ARRAY' eq $type ) { # Returns a list # (ELT ELT ELT ELT ELT) return '(' . join( ' ', map lisp( $_ ), @$thing ) . ')'; } elsif ( not defined $type ) { # Returns bare numbers. I don't think I need to deal with unde +rflow. return $thing if looks_like_float( $thing ); # Returns bare numbers if I think they won't overflow return $thing if length $thing <= 9 and looks_like_integer( $thing ); return qq["\Q$thing\E"]; } # Freely admit I can't handle anything fancy. die "Can't handle $type"; } sub looks_like_float { shift =~ /^-?\d+\.\d+\z/ } sub looks_like_integer { shift =~ /^-?\d+\z/ }

In reply to Perl data -> lisp data, very simply by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.