in reply to Re: foreach problem
in thread foreach problem

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Re: Re: foreach problem
by sacked (Hermit) on May 18, 2004 at 17:05 UTC
    Instead of map, you can use an inner for loop. Here, the inner loop adds four td's to an array (@table_cells). It then wraps @table_cells in a table row with Tr:
    use File::Basename; # ... while( my @cols= splice @files, 0, 4 ) { my @table_cells; + for( 0..3 ) { push @table_cells => $cols[$_] ? td( submit(-name=>'file', -value=> basename($cols[$_])) ) : td( ' ' ); } + print Tr( {-align=>'center'}, @table_cells ); }
    Or, again, use the distributive property of CGI's HTML functions:
    while( my @cols= splice @files, 0, 4 ) { my @table_cells; + for( 0..3 ) { push @table_cells => $cols[$_] ? submit(-name=>'file', -value=> basename($cols[$_])) : ' '; } + print Tr( {-align=>'center'}, td(\@table_cells) ); }

    --sacked
Re: Re: Re: foreach problem
by sacked (Hermit) on May 18, 2004 at 16:50 UTC
    The choice of loop constructs is up to you. I strongly recommend that you use File::Basename, however. It is a core module (i.e., it comes with Perl), and it does the job correctly, every time. It is also much easier for the average programmer to read and comprehend:
    $_ = basename( $_ );
    than
    $_ =~ s/.*[\/\\](.*)/$1/;

    --sacked