in reply to foreach problem

In each iteration of your foreach loop, $_ is set to one value in @files. As your call to Tr is inside the foreach loop, $_ has the same value in each td. You can use map to iterate over the list of files and get the results you want. Also, note the use of File::Basename::basename instead of a regular expression to remove the directory from the filenames:
use File::Basename; # ... # 4 elements at a time while( my @cols= splice @files, 0, 4 ) { print Tr( {-align=>'center'}, map { td( $_ ? submit(-name=>'file', -value=> basename($_)) : ' ' + ) } @cols[0..3] ); }
Or, use the distributive properties of the HTML shortcuts provided by CGI.pm (see the pod). In this case, we are passing a reference to a list of values to td, rather creating a list of calls to td:
use File::Basename; # ... while( my @cols= splice @files, 0, 4 ) { print Tr( {-align=>'center'}, td([ map { $_ ? submit(-name=>'file', -value=> basename($_)) : ' ' } @cols[0..3] ]) ); }

--sacked

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.