LTjake has asked for the wisdom of the Perl Monks concerning the following question:
Using data::dumper i get:opendir(DIRHANDLE, $self->param('photos_dir')) or die "couldn't open m +ain directory: $!"; $dir_row_count = 0; $file_count = 0; $row_limit = 5; while (defined($filename = readdir(DIRHANDLE))) { next if $filename =~ /^\.\.?$/ || !(-d $filename); push @$dir_list, { dir => $filename, dir_row => [] }; opendir(SUBDIRHANDLE, "$filename") or die "couldn't open directory + $filename: $!"; my @pictures = grep { /\.(?:png|gif|jpg)$/ } readdir SUBDIRHAN +DLE; closedir(SUBDIRHANDLE); push @{$dir_list->[scalar @$dir_list - 1]{dir_row}}, { file_row => + [] }; $file_count = 0; foreach (@pictures) { unless ($file_count % $row_limit) { push @{$dir_list->[scalar @$dir_list - 1]{dir_row}}, { fil +e_row => [] }; } push @{$dir_list->[scalar @$dir_list - 1]{dir_row}[$dir_row_co +unt]{file_row}}, { filename => "$filename/$_", alt => $_ }; $file_count++; } $dir_row_count++; }
$VAR1 = [ { 'dir' => '50s', 'dir_row' => [ { 'file_row' => [ { 'alt' => 'band_table.jp +g', 'filename' => '50s/band +_table.jpg' }, { 'alt' => 'cake_t2.jpg', 'filename' => '50s/cake +_t2.jpg' }, { 'alt' => 'cake-t.jpg', 'filename' => '50s/cake +-t.jpg' }, { 'alt' => 'an_logo.jpg', 'filename' => '50s/an_l +ogo.jpg' }, { 'alt' => 'gabe-bpm.jpg' +, 'filename' => '50s/gabe +-bpm.jpg' }, { 'alt' => 'cake_enter.jp +g', 'filename' => '50s/cake +_enter.jpg' } ] }, { 'file_row' => [] }, { 'file_row' => [] } ] }, { 'dir' => '60s', 'dir_row' => [ { 'file_row' => [] }, { 'file_row' => [ { 'alt' => 'cake_cdsleeve +.jpg', 'filename' => '60s/cake +_cdsleeve.jpg' } ] } ] } ];
Edit kudra, 2002-06-03 Added title given in ntc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Structure for nested html::template loops
by jeffa (Bishop) on Jun 02, 2002 at 01:27 UTC | |
|
Data::Grouper preps data for for HTML::Template
by markjugg (Curate) on Sep 01, 2002 at 23:50 UTC |