Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Perl Script question

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

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 27

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Six Sigma Control Plans

971 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