Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Sending Email

Reply
Thread Tools

Sending Email

 
 
gooofoofs
Guest
Posts: n/a
 
      04-20-2005
I have the following script parsing a log file for me. Im not sure how to
package this into an email. I prefer not to use modules.

#!/usr/bin/perl -w

my @code1;
my @code2;

open(FILE, "test.log");

while (<FILE>){
if($_ =~ m/code1\:\s(.*?)\s/){
print "<XML>\n";
print "<code1>$1</code1>\n";
}elsif($_ =~ m/code2\:\s(.*?)\s/){
print "<code2>$1</code2>\n";
print "</XML>\n\n";
}

close(FILE);


 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-20-2005
gooofoofs wrote:
> I have the following script parsing a log file for me. Im not sure how to
> package this into an email.


That's a FAQ.

perldoc -q "send mail"

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      04-20-2005
gooofoofs wrote:

> I have the following script parsing a log file for me. Im not sure how
> to
> package this into an email. I prefer not to use modules.
>
> #!/usr/bin/perl -w
>
> my @code1;
> my @code2;
>
> open(FILE, "test.log");
>
> while (<FILE>){
> if($_ =~ m/code1\:\s(.*?)\s/){
> print "<XML>\n";
> print "<code1>$1</code1>\n";
> }elsif($_ =~ m/code2\:\s(.*?)\s/){
> print "<code2>$1</code2>\n";
> print "</XML>\n\n";
> }
>
> close(FILE);



A non-perlish way I sometimes use is:-

perl myscript.pl | mail -s 'Mysubject line' http://www.velocityreviews.com/forums/(E-Mail Removed)


--
Brian Wakem

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-20-2005
gooofoofs <(E-Mail Removed)> wrote:

> Im not sure how to
> package this into an email.



What part of the FAQ answer are you having trouble with?

Show us the code that you tried, and we will help you fix it.


> I prefer not to use modules.



Why not?

If you don't provide a reason why best practices won't work for
your situation, then we can't really provide a work-around
applicable to your situation.


> #!/usr/bin/perl -w
>
> my @code1;
> my @code2;



Your program makes no use of those variables.


> open(FILE, "test.log");



You should always, yes *always*, check the return value from open():

open FILE, 'test.log' or die "could not open 'test.log' $!";


> while (<FILE>){
> if($_ =~ m/code1\:\s(.*?)\s/){



Colons are not special in regexes, there is no need to backslash them.

Whitespace is not a scarce resource, feel free to use as much of it
as you like to make your code easier to read.


if ( m/code1:\s(.*?)\s/ ) {


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      04-20-2005
Tad McClellan wrote:
> gooofoofs wrote:
>> Im not sure how to package this into an email.

>
> What part of the FAQ answer are you having trouble with?
>
>> I prefer not to use modules.

>
> Why not?
>
> If you don't provide a reason why best practices won't work for
> your situation, then we can't really provide a work-around
> applicable to your situation.


Uhmm.. Are people expected to assume that the first method mentioned in
the FAQ is a "work-around" and not best practices?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get the correct email format when sending email using sqldatareader rote ASP .Net 8 04-17-2008 02:14 AM
problem sending mail: Sending the email to the following server failed Luke Java 2 03-15-2007 10:54 AM
pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code.... shailajabtech@gmail.com Java 0 09-28-2006 06:38 AM
Sending email through Stored procedure Patrick ASP .Net 2 02-15-2005 08:29 AM
avoid sending pictures within email Zhang Weiwu (family name first) Firefox 1 09-11-2003 02:00 PM



Advertisments