Solved

Perl Script question

Posted on 2010-08-29
4
357 Views
Last Modified: 2013-12-26
Hi Experts,

I have this perl script its runs fine. My query is how do email this output. I am not good with using arrays.

Here is my code.


All i want is to send output which i am getting via array in email.


$query1 = $db4->prepare("SELECT COUNT (*), (
CASE WHEN PICSTATUS = '11' then 'Transfer Rejected'
when picstatus = '12' then 'Transfer Cancelled'
when picstatus = '20' then 'New Sale'
when picstatus = '70' then 'Pricing Accepted'
when picstatus = '72' then 'Sale Confirmed'
when picstatus = '80' then 'Ready for Transfer'
when picstatus = '90' then 'Transfer in progress'
end
) as STATUS FROM PROCONSUMER WHERE PICSTATUS NOT IN (100,10) GROUP BY PICSTATUS " );

$query1->execute;


while (@array = $query1->fetchrow_array)
{
 print "$array[1] = $array[0]\n";
#($ca) = $array[2];
}

# email

my $subject = " Daily stats";

my $message = " Customer Statistics \n =======================================================================
 ";


`/usr/bin/sendEmail -f stats\@abc.com.au -t abc\@abc.com.au -u $subject -s localhost -m " $message \n " `;

print "email sent";

Open in new window

0
Comment
Question by:santoshmotwani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 33555891
This should do it.  You can change some of the formatting by altering code...
$query1 = $db4->prepare("SELECT COUNT (*), (
CASE WHEN PICSTATUS = '11' then 'Transfer Rejected'
when picstatus = '12' then 'Transfer Cancelled'
when picstatus = '20' then 'New Sale'
when picstatus = '70' then 'Pricing Accepted'
when picstatus = '72' then 'Sale Confirmed'
when picstatus = '80' then 'Ready for Transfer'
when picstatus = '90' then 'Transfer in progress'
end
) as STATUS FROM PROCONSUMER WHERE PICSTATUS NOT IN (100,10) GROUP BY PICSTATUS " );

$query1->execute;

my @output;
while (@array = $query1->fetchrow_array)
{
    push @output, join("\t", @array);
}

# email

my $subject = " Daily stats";

my $message = " Customer Statistics\n =======================================================================\n" . join("\n ", @output);


`/usr/bin/sendEmail -f stats\@abc.com.au -t abc\@abc.com.au -u $subject -s localhost -m " $message \n " `;

print "email sent";

Open in new window

0
 
LVL 16

Author Comment

by:santoshmotwani
ID: 33555921
That worked awesome , this is what i got !!!
 53      Transfer Rejected


How do i get transfer rejected first and then count?
0
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 500 total points
ID: 33558352
The simplest way to change the order is to change the order in your query (eg put count(*) after the case).  Alternately, you can change line 17 to one of these:

push @output, join("\t", reverse @array);
push @output, join("\t", $array[1], $array[0]);
push @output, "$array[1]\t$array[0]";
0
 
LVL 16

Author Comment

by:santoshmotwani
ID: 33564675
Thnx Mate !!!!!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Six Sigma Control Plans

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question