Sending Email

G

gooofoofs

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);
 
G

Gunnar Hjalmarsson

gooofoofs said:
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"
 
B

Brian Wakem

gooofoofs said:
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' (e-mail address removed)
 
T

Tad McClellan

gooofoofs said:
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/ ) {
 
G

Gunnar Hjalmarsson

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


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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top