in reply to Joining, but skipping the last element
I have attempted to do this with join, but the code I was using was adding an AND at the end of the first element, and possibly the last one.it sounds like there's an empty element at the end of your list, resulting in an extra "and" at the end. may I suggest grepping? In the example, the first join shows the result of joining with a trailing empty element. The second one shows a way to join on grep, ensuring only non-blank (full?) elements get joined.
my @list = ("1","2","3",""); print join " and ", (@list); print "\n\n"; print join " and ", grep {$_?$_:undef} @list;
ooh! also, you could try an array slice! Of course, the above may be better for stripping out any nonblanks, but if you really just want to join an array sans the last element :
print join " and ", (@list[1,-2]);
|
|---|