Hi Monks,
Title may be a bit misleading. I know how to read the last line of the file, but what I want to know is the best method to detect it. I have a simple text file with a bunch of e-mail addresses:
blah@blah.com
blah@somedomain.com
blah@johndoe.com
Now I want to read this file and print it out so I can copy and paste to my e-mail program (outlook) and send them a announement. So I want to print the content of this textfile into a textarea to copy and paste.
Heres my code that reads the file, and prints line by line into the textarea.
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, ";
}
print "</textarea>";
Now heres my problem, the above code prints this into the textarea:
blah@johndoe, blah@somedomain.com, blah@blah.com,
Notice the comma at end (blah@blah.com
,), how can I detect the end of the line of this file so I can tell Perl not to print the last "," ? So basically I want the contents of textarea to look like this
blah@johndoe, blah@somedomain.com, blah@blah.com
I'm building this as a add-on to a newsletter script so my friend (whose not really good with computers) can goto this script and copy the e-mails from the textarea box and paste it directly into her Outlook address. I really would like to learn this and give her extra convenience by not having her delete the last trailing "," manually.
Thanks Monks
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.