Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: foreach problem

by sacked (Hermit)
on May 18, 2004 at 14:43 UTC ( [id://354284]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://354284]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found