Professional Web Applications Themes

Could anyone please help with Line Extraction and Emailing Question - PERL Beginners

Sunish Kapoor wrote:  <snip>   Where is use strict; # which requires that variables are declared use warnings; ?? <snip>   So, what do you think %hash contains after the while loop? You should have printed it here in order to check. If you had done so, you'd probably have found that it only contains two of the lines. Maybe this is what you intended to do: push { $hash{$fields[1]} }, [ fields[0,2..9] ]; (note that this requires changes in mail_report(), too) -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl...

  1. #1

    Default Re: Could anyone please help with Line Extraction and Emailing Question

    Sunish Kapoor wrote: 

    <snip>
     

    Where is

    use strict; # which requires that variables are declared
    use warnings;

    ??

    <snip>
     

    So, what do you think %hash contains after the while loop? You should
    have printed it here in order to check. If you had done so, you'd
    probably have found that it only contains two of the lines.

    Maybe this is what you intended to do:

    push { $hash{$fields[1]} }, [ fields[0,2..9] ];

    (note that this requires changes in mail_report(), too)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  2. #2

    Default Re: Could anyone please help with Line Extraction and Emailing Question

    Sunish Kapoor wrote: 

    These are my suggested changes:
     

    Replace that line with:

    push { $hash{$fields[1]} }, [ fields[0,2..9] ]
    if $fields[10] == $epoch;

    Then you need an inner foreach loop inside the current foreach loop in
    the mail_report() function.
     

    foreach my $line ( 0 .. $#{ $hash{$key} } ) { # inner loop begins
     

    Change that line to:

    print MAIL "To: <$hash{$key}[$line][0]>\n";
    --------------------------------^^^^^^^

    <snip>
     

    Change that line to:

    <td><center>$hash{$key}[$line][2]</center></td>
    ---------------------------^^^^^^^
     

    (Similar changes to all those lines.)

    } # inner loop ends
     

    That's it.

    %hash is now a hash of arrays of arrays ( previously it was a 'simple'
    hash of arrays ;-) ). Start learning about Perl data structures at
    http://www.perldoc.com/perl5.8.4/pod/perldsc.html

    There is a lot more to say about your script, but I stop here for now.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  3. #3

    Default Re: Thanks a Ton..Mr Gunnar..

    Sunish Kapoor wrote: 

    You're welcome, glad it works.
     

    The best way to thank me, and bring additional value to this
    community, is to post an updated script including "use strict;" and
    "use warnings;", where you have made the adjustments that strictures
    and warnings alerted you to do. ;-)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  4. #4

    Default Could anyone please help with Line Extraction and Emailing Question

    I have been struggling with a script but cant make it work.

    There are two Sales Executives called :

    Randal & Tom

    Randal's Email ID is > com

    Tom's Email ID is > com

    Below are the contents of a text file called prospects.txt

    You'll observe that there are six lines for Randal and six lines for Tom.

    The second last field is the date field in mm/dd/yy and the last field is time in EPOCH seconds
    as per date in second last field.

    Today is July 16 so when script should be executed it should send line1, line3, line5 to Randal on com

    Similarly it should send line7, line9, line11 to Tom on com

    NOW THE PROBLEM => Though it is sending email but only line5 to Randal and line11 to Tom

    I cant figure out and solve this !

    I look forward to your help on this

    Thanks & regards

    Sunish Kapoor

    -------------------------------------------------prospects.txt below

    com%%Randal%%7/10/2004%%Services & Trade%%Mr Sarathi%%Manager%%7711455%%Renewal - Gold Membership%%75%%7/16/2004%%1089961200
    com%%Randal%%7/10/2004%%Abu Zaki%%Mr Jauqim%%I T Manager%%7730611%%Gold Membership + Banner%%125%%7/10/2004%%1089403200
    com%%Randal%%7/10/2004%%Medical Supplies%%Ms Priya%%Asst Manager%%7715771%%Gold Membership + Banner%%125%%7/16/2004%%1089961200
    com%%Randal%%7/10/2004%%Intl Stationery%%Mr Khalid Shanfari%%Manager%%701302%%Platinum membership%%210%%7/12/2004%%1089576000
    com%%Randal%%7/10/2004%%Salah Cooler%%Mr. Vijay Nirula%%General Manager%%701721%%Gold membership%%75%%7/16/2004%%1089961200
    com%%Randal%%7/10/2004%%Insurance Center%%Mr Ravi Shankar%%General Manager%%792923%%Gold Membership%%75%%7/12/2004%%1089604800
    com%%Tom%%7/10/2004%%Al Batinah Int SAOG%%Mr Fairuz%%General Manager%%783388%%Gold Membership%%75%%7/16/2004%%1089961200
    com%%Tom%%7/10/2004%%Qatar Airways%%Mr Ali Khalid Shanfari%%Area manager%%785843%%Gold Membership%%75%%7/12/2004%%1089576000
    com%%Tom%%7/10/2004%%Asha Ent (cont)%%Mr. Domnic %%A/c Manager%%568591%%Gold Membersahip%%75%%7/16/2004%%1089961200
    com%%Tom%%7/10/2004%%Renaissance%%Mr Arindam Roy%%Manager%%796636%%Platinum Membership%%210%%7/10/2004%%1089403200
    com%%Tom%%7/10/2004%%Muscat General Ent%%Mr Joseph%%Manager%%700667%%Gold Membership%%75%%7/16/2004%%1089961200
    com%%Tom%%7/10/2004%%Global Finance Investment%%Mr. Milind%%Manager%%7716960%%Gold Membership%%75%%7/20/2004%%1090296000

    -------------------------Below is the SCRIPT-------------------

    #!c:/perl/bin/perl

    use Time::Local;

    $sendmail = "c:/sendmail/sendmail.exe"; #where sendmail lives on my WindowsXP

    $file = "c:/prospects.txt";

    $epoch = timelocal($mday, $month, $year, (localtime)[3,4,5]);

    &curtime;

    sub curtime

    {

    ($a,$b,$c)=(localtime(time))[3,4,5];

    $c = $c + 1900;

    $thetime = timelocal(0,0,0,$a,$b,$c);

    return($thetime);

    }

    %hash=();

    open (FILE, "<$file");

    while ($line = <FILE>)

    {

    chomp;

    fields = split (/%%/, $line);

    $hash{$fields[1]}= [$fields[0],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7],$fields[8],$fields[9]] if ($fields[10] == "$epoch" ) ;

    }

    close (FILE);

    &mail_report;

    sub mail_report

    {


    foreach my $key (keys %hash) {
    open (MAIL, "|$sendmail -t");
    print MAIL "Return-Path: sunish\umsoman.com\n";
    print MAIL "To: <$hash{$key}[0]>\n";
    print MAIL "From: sunish\umsoman.com\n";
    print MAIL "Subject:$key >> Your Prospects Report\n";
    print MAIL "Content-Type: text/html\n\n";
    print MAIL "<html>\n";
    print MAIL "<body>\n";
    print MAIL "<center><h3> $key Your Prospects</h3><hr>

    <table border=1>
    <tr><center>
    <td><center><h3>COMPANY</h3></center></td>
    <td><center><h3>CONTACT</h3></center></td>
    <td><center><h3>TITLE</h3></center></td>
    <td><center><h3>PHONE</h3></center></td>
    <td><center><h3>PROSPECT FOR</h3></center></td>
    <td><center><h3>VALUE</h3></center></td>
    <td><center><h3>EXP DATE</h3></center></td>
    </h3></center></tr>";

    print MAIL"<tr>

    <td><center>$hash{$key}[2]</center></td>
    <td>$hash{$key}[3]</td>
    <td>$hash{$key}[4]</td>
    <td>$hash{$key}[5]</td>
    <td><center>$hash{$key}[6]</center></td>
    <td><center>$hash{$key}[7]</center></td>
    <td><center>$hash{$key}[8]</center></td>
    <td><center>$hash{$key}[9]</center></td>\n";

    }
    print MAIL"</td></tr></table></center>";
    print MAIL "</body>\n";
    print MAIL "</html>\n";
    close (MAIL);

    }

    sleep (1);
    print "Content-type: text/html\n\n"; #HTML response
    print "Message Sent\n";

    -------------------------------------------------------------







    Sunish Guest

  5. #5

    Default Re: Could anyone please help with Line Extraction and Emailing Question

    Hello,

    Still cant figure out..and make it work.. could anyone pls modify this for
    me for me !

    Do not know how to make change in sub mail_report too

    Sunish

    ----- Original Message -----
    From: "Gunnar Hjalmarsson" <cc>
    To: <org>
    Sent: Friday, July 16, 2004 5:28 AM
    Subject: Re: Could anyone please help with Line Extraction and Emailing
    Question

     
    >
    > <snip>
    > [/ref]
    Sarathi%%Manager%%7711455%%Renewal - Gold
    Membership%%75%%7/16/2004%%1089961200 [/ref]
    Manager%%7730611%%Gold Membership + Banner%%125%%7/10/2004%%1089403200 [/ref]
    Manager%%7715771%%Gold Membership + Banner%%125%%7/16/2004%%1089961200 [/ref]
    Shanfari%%Manager%%701302%%Platinum membership%%210%%7/12/2004%%1089576000 [/ref]
    Nirula%%General Manager%%701721%%Gold membership%%75%%7/16/2004%%1089961200 [/ref]
    Shankar%%General Manager%%792923%%Gold Membership%%75%%7/12/2004%%1089604800 [/ref]
    Manager%%783388%%Gold Membership%%75%%7/16/2004%%1089961200 [/ref]
    manager%%785843%%Gold Membership%%75%%7/12/2004%%1089576000 [/ref]
    Manager%%568591%%Gold Membersahip%%75%%7/16/2004%%1089961200 [/ref]
    Roy%%Manager%%796636%%Platinum Membership%%210%%7/10/2004%%1089403200 [/ref]
    Joseph%%Manager%%700667%%Gold Membership%%75%%7/16/2004%%1089961200 [/ref]
    Milind%%Manager%%7716960%%Gold Membership%%75%%7/20/2004%%1090296000 
    >
    > Where is
    >
    > use strict; # which requires that variables are declared
    > use warnings;
    >
    > ??
    >
    > <snip>
    > [/ref]
    [$fields[0],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7
    ],$fields[8],$fields[9]] 
    >
    > So, what do you think %hash contains after the while loop? You should
    > have printed it here in order to check. If you had done so, you'd
    > probably have found that it only contains two of the lines.
    >
    > Maybe this is what you intended to do:
    >
    > push { $hash{$fields[1]} }, [ fields[0,2..9] ];
    >
    > (note that this requires changes in mail_report(), too)
    >
    > --
    > Gunnar Hjalmarsson
    > Email: http://www.gunnar.cc/cgi-bin/contact.pl
    >
    > --
    > To unsubscribe, e-mail: org
    > For additional commands, e-mail: org
    > <http://learn.perl.org/> <http://learn.perl.org/first-response>
    >
    >
    >[/ref]

    Sunish Guest

  6. #6

    Default Thanks a Ton..Mr Gunnar..

    Dear Mr Gunnar,

    Thanks a million..it works great now

    Thank you so much for your prompt support via email

    Regards

    Sunish Kapoor
    Muscat, Oman


    ----- Original Message -----
    From: "Gunnar Hjalmarsson" <cc>
    To: <org>
    Sent: Friday, July 16, 2004 8:36 AM
    Subject: Re: Could anyone please help with Line Extraction and Emailing
    Question

     
    >
    > These are my suggested changes:
    > [/ref]
    [$fields[0],$fields[2],$fields[3],$fields[4],$fields[5],$fields[6],$fields[7
    ],$fields[8],$fields[9]] if ($fields[10] == "$epoch" ) ; 
    >
    > foreach my $line ( 0 .. $#{ $hash{$key} } ) { # inner loop begins

    >
    > Change that line to:
    >
    > print MAIL "To: <$hash{$key}[$line][0]>\n";
    > --------------------------------^^^^^^^
    >
    > <snip>

    >
    > Change that line to:
    >
    > <td><center>$hash{$key}[$line][2]</center></td>
    > ---------------------------^^^^^^^

    >
    > (Similar changes to all those lines.)
    >
    > } # inner loop ends

    >
    > That's it.
    >
    > %hash is now a hash of arrays of arrays ( previously it was a 'simple'
    > hash of arrays ;-) ). Start learning about Perl data structures at
    > http://www.perldoc.com/perl5.8.4/pod/perldsc.html
    >
    > There is a lot more to say about your script, but I stop here for now.
    >
    > --
    > Gunnar Hjalmarsson
    > Email: http://www.gunnar.cc/cgi-bin/contact.pl
    >
    > --
    > To unsubscribe, e-mail: org
    > For additional commands, e-mail: org
    > <http://learn.perl.org/> <http://learn.perl.org/first-response>
    >
    >
    >[/ref]

    Sunish Guest

Similar Threads

  1. Multi-line update question
    By Jim in forum Dreamweaver AppDev
    Replies: 1
    Last Post: March 31st, 09:29 PM
  2. Newbie question about new line
    By Wim in forum PHP Development
    Replies: 5
    Last Post: October 1st, 05:55 PM
  3. command line question.
    By Dmitrii PapaGeorgio in forum Ruby
    Replies: 5
    Last Post: September 30th, 06:12 PM
  4. OS/2 line feed question
    By Alan J. Flavell in forum PERL Miscellaneous
    Replies: 6
    Last Post: August 21st, 01:08 AM
  5. Replies: 2
    Last Post: July 3rd, 07:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139