Hi,

>From your question I understand that you are looking for the join commang:

my $var = join ("delimiter",[EMAIL PROTECTED]);

Hope that helps

Yaron Kahanovitch
----- Original Message -----
From: "Romeo Theriault" <[EMAIL PROTECTED]>
To: beginners@perl.org
Sent: 23:39:22 (GMT+0200) Asia/Jerusalem יום חמישי 17 מאי 2007
Subject: Store contents of array in a variable?

This is probably a dumb question but is it possible to store the
contents of an array into a variable?

Something like this:

$variable = foreach $array_ref7 (@rowstash7) {
       return "@$array_ref7\n";
    }

I have this script below in which I am trying to send the contents of an
array within an email and don't quite know how to deal with getting the
contents of the array's into the email message. Suggestions are very
welcome.

Thanks,

Romeo


#!/usr/bin/perl

use warnings;
use strict;
use DBI;
use Net::SMTP;


my @rowstash7;
my @rowstash30;
my @rowstash365;
my $array_ref7;
my $array_ref30;
my $array_ref365;
my $somevariable = "test";


## Connect to the database.
my $dbh = DBI->connect( "DBI:mysql:database=antivirus;host=localhost",
    "user", "password", { 'RaiseError' => 1 } );

&success_querie(7);
&success_querie(30);
&success_querie(365);

&sendmail('[EMAIL PROTECTED]',
'[EMAIL PROTECTED]', "Antivirus Downloads", 'mail.maine.edu',
'[EMAIL PROTECTED]', "Download Activity for the last
Week:\n$somevariable\n\nDownload Activity for the last
Month:\n$somevariable\n\nDownload Activity for the last
Year:\n$somevariable");



## Function to query the database for the info.
sub success_querie {
    my ($searchlength) = @_;
    my $select_handle =
      $dbh->prepare_cached(
'SELECT name,COUNT(*) FROM success WHERE datetime > SUBDATE(NOW(),
INTERVAL ? DAY) GROUP BY name;'
      );

    die "Couldn't prepare queries; aborting"
      unless defined $select_handle;

    $select_handle->execute($searchlength) or return 0;
    my ( $name, $count );
    $select_handle->bind_columns( \$name, \$count );

    if ( $searchlength == 7 ) {
        while ( $array_ref7 = $select_handle->fetchrow_arrayref() ) {
            push @rowstash7, [EMAIL PROTECTED];

            #print "$name, $count\n";
        }
    }
    elsif ( $searchlength == 30 ) {
        while ( $array_ref30 = $select_handle->fetchrow_arrayref() ) {
            push @rowstash30, [EMAIL PROTECTED];

            #print "$name, $count\n";
        }
    }
    else {
        while ( $array_ref365 = $select_handle->fetchrow_arrayref() ) {
            push @rowstash365, [EMAIL PROTECTED];

            #print "$name, $count\n";
        }
    }

    $select_handle->finish();

    return 1;    # Success

    ## Disconnect from the database.
    $dbh->disconnect();

}

## Function to send the mail.
sub sendmail {
    my ( $from, $to, $subject, $server, $replyto, $message ) = @_;
    my $smtp = Net::SMTP->new($server);
    $smtp->mail($from);
    $smtp->to($to);

    #$smtp->bcc($bcc, $bcc1);
    $smtp->data();
    $smtp->datasend("To: $to\n");
    $smtp->datasend("Subject: $subject\n");
    $smtp->datasend("Reply-To: $replyto\n");
    $smtp->datasend("$message");
    $smtp->dataend();

    $smtp->quit;
}

#sub messagebody {
#       Print "Download Activity for the last Week:\n";
#       foreach $array_ref7 (@rowstash7) {
#          return "@$array_ref7\n";
#       }
#       print "Download Activity for the last Month:\n";
#       foreach $array_ref30 (@rowstash30) {
#          return "@$array_ref30\n";
#       }
#       print "Download Activity for the last Year:\n";
#       foreach $array_ref365 (@rowstash365) {
#               return "@$array_ref365\n";
#       }
#}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to