I have a series of files which are auto-generated hourly, based on commits from developers and community members who maintain these files. Currently there are 14 languages that we support. Our public website has a page which contains links to these files, including filename, size, and date of the file itself, so users who wish to use these "snapshots", can make sure they are current, etc.

To do this, I'm currently rolling through a directory where these files are placed, and fetching the information as follows:

find( { untaint_pattern=>'.*', no_chdir => 1, preprocess => sub {sort @_}, wanted => sub { return unless /\.(prc|pdb)\z/; my $v_snap_file = $File::Find::name; my $v_sb = stat("$v_snap_file"); my $v_filesize = $v_sb->size; my $v_bprecise = sprintf "%.0f", ($v_filesize); my $v_bsize = insert_commas($v_bprecise); my $v_kprecise = sprintf "%.0f", ($v_filesize/1024); my $v_ksize = insert_commas($v_kprecise); my $v_filedate = strftime "%D %r", localtime $v_sb->mtime; my $basename_v = basename($v_snap_file); print $cgi->blockquote( $cgi->a({-href=>"snapshots/$basename_v"}, "$basename_v"), $cgi->br(), "File size: $v_bsize bytes ($v_ksize kb)", $cgi->br(), "File date: $v_filedate", $cgi->br()); print "\n"; } }, $root);

This part works, but produces a very lengthy list of files, in a non-human ordering.

What I'd like to do, is compress that output a bit, so that I have a hash (??) lookup of the languages, which are then tacked onto the filename (so "English" matches up with strings_en.txt, Spanish matches up with strings_es.txt). We know the extensions of the languages we support (_es for Spanish, _fr for Francais, etc.).

Ideally, the output would look something like this:

Chinese [<a href="foo_zh_CN.txt">txt</a>] Size: 6,016 bytes Deutsch [<a href="foo_de.txt">txt</a>] Size: 277,175 bytes

The piece of this that I'm struggling with, is how to make the "human" names (English, Deutsch, French) match up with the file extensions (_en, _de, _fr respectively), and then for each of those (${file}${lang}.txt), find the file size and date (File::Find here), and output them in alphabetical order by their "human" names (Catalan before Chinese, etc.)

Any hints/tips that would help?


In reply to Hashes, File sizes, Translations, OH MY! by hacker

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.