Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Don't print on the last loop

by jeffa (Bishop)
on Jun 13, 2005 at 14:14 UTC ( [id://466170]=note: print w/replies, xml ) Need Help??


in reply to Don't print on the last loop

If the code is not terribly complex, you can always use join. If it is, consider pulling out the last element (with pop) and saving it for after the loop. You will most likely want to encapsulate the body of the loop into a subroutine. Something like this:

my $last = pop @tables; foreach my $table (@tables) { process($dbh,$table); print ",\n"; } process($dbh,$last);

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2025-05-24 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.