We provide .torrent downloads for each of these as well, for both the .zip, .bz2, and .rpm files, and we crank out new releases roughly every month. It gets pretty busy around release time. That brings our total number of links to edit/create to 88 for each release cycle. Add the need to create 5 links for every file for local, torrent, and mirrors, and it gets unweildly.
That being said, I'd like to find a better way to present these on the website. We have several community users who have provided some of their own webspace/bandwidth for mirrors, and on our download page, we have links for each of these packages, per-mirror, per-version (stable vs. unstable). It gets ungainly when a new release is made, having to update the versions, titles, descriptions and so on.
Enter.. HASHES! I'm really horrible at hashes, and I try to stay away from them as much as possible, but I think it is now time for me to give in and learn them.
What I need some ideas for, is the best way to present these downloads, in a logical, scalable way, on our download page, in perl.
I've begun reducing the mirror links by putting them into an array, and randomizing across them, like this:
my $stable = "1.8"; my $unstable = "1.7.2"; my @mirrors = ('http://www.foo.com/bar/stable', 'http://stable.example.com', 'http://downloads.site.org/$stable', 'http://www.unmetered.org/data', ); print "Mirror: $mirrors[rand @mirrors]";
This works of course, and reduces 4 lines of links per-package down to one.
The next problem.. I need a way to roll through the "types" of packages we offer, and then output the link, title, size, and so on, dynamically, per-release (stable vs. unstable). So far, what I have looks like this (thanks to diotalevi for helping me figure most of this out):
my @releases = ( { name => 'Runtime RPM', desc => 'Includes viewer and Python distiller', versions => [{ version => $stable, files => [ "foo-$stable-1.i386.rpm"] }] # versions }, #name { name => 'Source RPM', desc => 'Includes viewer and Python distiller', versions => [{ version => $unstable, files => [ "foo-$stable-1.src.rpm"] }] # versions }, # name { name => 'Viewer in English', desc => '', versions => [{ version => $unstable, files => [ "foo-$unstable.torrent", "foo-$unstable.zip", "foo-$unstable.tar.bz2"] }] # versions }, # name ); foreach my $release (@releases) { my $versions = $release->{'versions'}; foreach my $version (@$versions) { my $files = $version->{'files'}; my $mirror = $mirrors[rand @mirrors]; foreach my $file (@$files) { print "$release->{'desc'}\n\t"; print "$version->{'version'}\n\t"; print "$file\n\t"; print "Mirror: $mirror/$file\n\n"; } } }
The problem with this piece.. is that there is no clear separation of unstable vs. stable, nor is there an easy way to tell it to print them in a specific order. Let me explain:
I would like to call this code, and pass it two parameters, like "Documentation, stable", and then have it return the values which match, so I can foreach through them, as above, for that "type" of download. I would then call it again for "RPM", "Viewer", and so on.
Also, when printing the "unstable" downloads, I should be able to just call that (function?) over and over, passing it an array of values or something (not sure how to word this properly to describe what I'm conceiving).
Can I pass it something like:
my @types = ('Runtime RPM', 'Source RPM', 'Viewer', 'Distiller', 'Documentation', 'Source', 'Extras');
..and have it "walk" across that array, and for each value found, look it up in the hash that contains the corresponding name/package, and print the values found (name, description, file, etc.)
Did that make sense? I'm sure there are a few ways to do this. I'm interested in hearing them all.
In reply to A Hash is a Hash (of course, of course) by hacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |