I re-kid you, Almut: eval, untainted, unrestricted??

Could you do a quick replace of <DATA> with <>, with piped input from find for me, and then permit me a run of a single perl -e. Just before you execute your script?

:>>

(ok, it's _DATA_ and thus controlled, but it still hurts on reading. And worse, that one is pure evil to both speakers of Perl and non-speakers alike)

Update: to restrict the hurt to mere aesthtics, consider this safer version of the input loop, which will also survive pasted arbitrary absolute pathes from DATA/or a switch from DATA to STDIN.

my @f=(); # PJ while (<DATA>) { chomp; s|([^/]+)|do{$f[$#f+1]=$1,'$f['.$#f.']'}|ge; # PJ s|^/|\$h->{|; s|/|}{|g; s|$|} = 1;|; # PJ #print; print "\n"; eval; }

food for thought

  1. make 'tokenization' of filenames reuse 'tokens'
  2. fix the loop to allow relative filenames (too trivial)
  3. portability: also allow c:\data\no-such.fil
  4. not a task, but an observation: use of Data::Dumper shows nicely the data structure of the recursive anonymous hash almut uses. This also demonstrates Perl's auto-vivication of the anonymous hashes we use hre: there's not one assignment of {}:
    $h->{$f[19]}{$f[20]}{$f[21]}{$f[22]} = 1;
  5. a remark: normally you'd go for recursive functions when parsing a single path into a list of -> tree nodes. Or for a slightly less readable iterative 'unrolled' version of the same (keywords tail-recursion, loop-unrolling). The above code actually can be seen as such: everything but the s|/|}{|g; has been moved outside the loop, with the loop being reduced to just a looping regex substitution (/g modifier). Not much of a loop, not much for readability, and definitely not a sane nor a correct answer to give :)

      In reply to Re^2: Creating table from file lists by jakobi
      in thread Creating table from file lists by affc

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



    1. Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
    2. Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
    3. Read Where should I post X? if you're not absolutely sure you're posting in the right place.
    4. Please read these before you post! —
    5. 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
    6. 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;
    7. Link using PerlMonks shortcuts! What shortcuts can I use for linking?
    8. See Writeup Formatting Tips and other pages linked from there for more info.