in reply to Detecting Last line of a file
Update: It isn't the best way, isn't even a good way. See later in the thread for better solutions. Doh!
my $file = "emails.txt"; open(FILE, $file) or die "cannot open $file : $!\n"; @content = reverse (<FILE>); close FILE; print "<textarea cols=\"75\" rows=\"22\">"; foreach $address (@content) { chomp($address); print $address; if ($address ne $content[-1]){print ", "} } print "</textarea>";
(In other words, print the comma unless its the last line). That assumes that each element in @content is unique. Given that you are using them for a mailing list, that should be a valid assumption. If not:
.. my $counter=0; foreach $address (@content) { chomp($address); print $address; $counter++; if ($counter < @content){print ", "} } ..
Set a counter and print the comma if the counter is smaller than the number of elements in the array.
--------------------------------------------------------------
g0n, backpropagated monk
|
|---|