S
ShaunJ
I want to print a separator between each iteration of a foreach loop,
but not after the last element. How do I avoid printing the last
extraneous comma in the following code snippet?
foreach (@ARGV) {
print $_, ',';
}
print "\n";
In this simple example join ',' would suffice, but the real body of
the foreach loop is more complicated. What I want to do is something
like this:
foreach (@ARGV) {
print $_;
print ',' unless last_element;
}
print "\n";
Thanks,
Shaun
but not after the last element. How do I avoid printing the last
extraneous comma in the following code snippet?
foreach (@ARGV) {
print $_, ',';
}
print "\n";
In this simple example join ',' would suffice, but the real body of
the foreach loop is more complicated. What I want to do is something
like this:
foreach (@ARGV) {
print $_;
print ',' unless last_element;
}
print "\n";
Thanks,
Shaun