I'd make two minor adjustments to your one-liner plus one major one and fix one bug:

perl -MStorable -ne 's/(.)/\{$1\}/g;eval­("\$x$_\{­EOS}=0");END{sto­re +(\%x,out­put)}' # (Perl not sed)^ prettier^^^ bug^^ ^^^^was quit +e wasteful

Regarding

I'll make one-liners out of those :)

Just because it is a one-liner doesn't mean it has to suck as code (using string-eval like that). ;) The approaches I've used (for example in Re: find all paths of length n in a graph (Boggle solver)) fit easily as one-liners. I've replaced your 'EOS' with a more universal "end of" string, "\n".

perl -MStorable -ne '$p=\%t;$p=$p->{$_}||={}for/./gs;END{sto­re(\%t,ou +t­put)}'

That doesn't even autovivify.

Here's another version for those who don't care about the 'store to file' step (with extra verbosity to overcome Data::Dumper's extremely ugly defaults and to provide sample input). Note that here I use an earlier approach of mine so I can have the end-of-word entry point to a false value instead of to an empty hash.

grep '^s\?[hk]\?[ei][ln][tlk]y\?$' /usr/share/dict/words | perl -MData +::Dumper -ne '$p=\\%t;$p=\$$p->{$_}for/./gs;$$p=0;END{print Data::Dum +per->new([\%t])->Terse(1)->Indent(1)->Sortkeys(1)->Useqq(1)->Dump()}' + | less

- tye        


In reply to Re^3: Lexicographic tree (betters) by tye
in thread Lexicographic tree by pierre.marchal

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.