Sending Email

Discussion in 'Perl Misc' started by gooofoofs, Apr 20, 2005.

  1. gooofoofs

    gooofoofs Guest

    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);
     
    gooofoofs, Apr 20, 2005
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Apr 20, 2005
    #2
    1. Advertising

  3. gooofoofs

    Brian Wakem Guest

    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'


    --
    Brian Wakem
     
    Brian Wakem, Apr 20, 2005
    #3
  4. gooofoofs <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 20, 2005
    #4
  5. 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
     
    Gunnar Hjalmarsson, Apr 20, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick
    Replies:
    2
    Views:
    5,989
    Gopinath S
    Feb 15, 2005
  2. =?Utf-8?B?dWZyYWY=?=

    sending email thro SMTP server

    =?Utf-8?B?dWZyYWY=?=, May 20, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,773
    =?Utf-8?B?dWZyYWY=?=
    May 30, 2005
  3. Replies:
    0
    Views:
    1,470
  4. Luke
    Replies:
    2
    Views:
    4,811
    Nigel Wade
    Mar 15, 2007
  5. rote
    Replies:
    8
    Views:
    796
Loading...

Share This Page