use 5.008; use strict; use warnings; use IO::Handle; use Text::CSV; use JSON; # A nested hash of groups my %hierarchy; # Parse the CSV input data into %hierarchy { my $csv = new Text::CSV(); while (my $fields = $csv->getline(\*DATA)) { my ($article, @groups) = @$fields; my $anchor = \%hierarchy; foreach (@groups) { $anchor->{$_}->{__name__} = $_; $anchor = $anchor->{$_} } push @{$anchor->{__articles__}}, $article; } die sprintf("Error parsing CSV input: %s\n", $csv->error_diag()) unless ($csv->eof()); } # Convert the hierarchy data into JS format my $hierarchy_json = do { my $json = new JSON(); $json->utf8(1)->pretty(1); $json->encode(\%hierarchy); }; # Print the HTML page print < Article Catalog

Article Catalog

Group Selection