hacker has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Hashes, File sizes, Translations, OH MY!
by thor (Priest) on May 29, 2004 at 16:12 UTC | |
Re: Hashes, File sizes, Translations, OH MY!
by SciDude (Friar) on May 30, 2004 at 01:39 UTC |