in reply to Re^2: HTML::Template output to files.
in thread HTML::Template output to files.

I see, but I cant get the value for $entry->{'NAME'} unless I am inside of the WHILE and since there will be lots of files been created I need to use the value of $key to name these files. The value of $entry->{'NAME'} is one per file, it does not need to be in a loop. Once I have all the data pushed into the @data array how it would be possible to create the files for each $entry->{'NAME'} ?

Replies are listed 'Best First'.
Re^4: HTML::Template output to files.
by Anonymous Monk on Apr 28, 2014 at 21:56 UTC

    If you can provide a sample of your data that would help in giving a precise answer (use Data::Dumper; print Dumper($more_data);). In addition, try some things out yourself and post here if you have questions about the code. I think the general concept would be something like this:

    while ( my ($key,$name) = get_key_and_name() ) { my @data; while ( my ($entry) = get_data_for_key($key) ) { push @data, { NUMBER => $entry->{NUMBER}, etc=>"etc" }; } my $data_tmpl = HTML::Template->new(filename => 'data.tmpl'); $data_tmpl->param(NAME => $name, DATA => \@data); write_file("/location/$key.html", $data_tmpl->output); }

    (once again untested and based only on the docs - just trying to show the concept of nested while loops here)

    Without knowing what $more_data looks like, I can't say what the placeholders get_key_and_name() and get_data_for_key() should look like.