Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl Script question

Posted on 2010-08-29
4
Medium Priority
?
364 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 2000 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

721 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