On Tuesday 02 September 2003 10:50, Marshal Newrock wrote:
> On Mon, 1 Sep 2003, Jason wrote:
> > above, what I want to do is:
> >
> > @sometext = ("text\n\with\nmore\nthan\none\nnewline\n",
> > "some\nother\nline\n");
> > @newtext = ("text\n", "with\n", "more\n", "than\n", "one\n", "newline\n",
> > "some\n",
> > "other\n", "line\n");
> > #Do something magic to @sometext here to make it turn into @newtext
>
> Just two things:
> 1) perldoc -f split
> 2) man perlfunc
>
> Perl typically excels at text processing. You can also look at the
> 'join' command if you wish. But certainly 'man perlfunc' along with
> 'perldoc -f $function_name' will let you go far with your scripts. :)
Sorry for the extremely late reply. Thanks for the info. I eventually used it
to write a working script, which I have included below.
I was using "man perl*" quite often. I haven't read all the way through
anything except perlintro yet though. I find when looking up language
reference, you have to know what you want to be able to find it. That is to
say, I don't tend to search for how a function works unless I expect the
function to exist. Needless to say, I didn't think the function to exist -
even though I knew that perl's forte is text-processing. This is my first
attempt at anything in perl, too!
Still a bit of functionality to add before I'll be happy - but I'll do that as
needed. There's also two bugs, one small and one big, but I'll work on those
independently until I get too frustrated. ;-)
I do have a couple of questions which I haven't been able to find the answer
to. I've embedded them within the code.
#!/usr/bin/perl
use Mail::Internet;
use HTML::Parser;
$mail = Mail::Internet->new(*STDIN);
$mail_head = $mail->head();
$msg_date = $mail_head->get("Date");
$msg_from = $mail_head->get("From");
$msg_subj = $mail_head->get("Subject");
$mail->tidy_body();
# Can I combine the following two lines in any way?
# $mail_body = @$mail->body(); does not work.
$mail_body_ref = $mail->body();
@mail_body = @$mail_body_ref;
@body_text = "";
$body_pars = HTML::Parser->new(
text_h => [sub
{
$text = shift;
if ($text =~ /[0-9a-zA-Z]/) {
@body_text = (@body_text, $text);
}
}, 'dtext']);
foreach (@mail_body) {
$body_pars->parse("$_");
}
$body_pars->eof();
@body_text = split("\n", join(" ", @body_text));
@ntfy_mail = ("Date: $msg_date",
"From: $msg_from",
"Subject:$msg_subj",
"\n");
# Can I combine this into one line? Can I combine it with the above?
for ($i = 0; $i < 20; $i++) {
@ntfy_mail = (@ntfy_mail, "@body_text[$i]\n");
}
open(XMAIL, "| mail -s 'Mail Notification' [EMAIL PROTECTED]");
print XMAIL @ntfy_mail;
close(XMAIL);
Thanks for all your help!
Jason
--
[EMAIL PROTECTED] mailing list