Solved

Perl Script question

Posted on 2010-08-29
4
325 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
  • 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now