I am really stuck here. I need to split values from a csv value and push
them into an array, then perform a routine for all of them in a foreach
statement. In this example I am reading an email address, a username and a
password and needing to send each user listed in the csv a mail to the email
address with the message containing their username and password. I am
successful in reading the lines of the file and the ability to iterate
through them with once they are in the array, but then how do I get them
into variables to be used by the sub? Again in this example, I need to
create a variable ($to) from the first value, a username ($username) from
the second value and a password($password) from the third value. Those
variables will obviously be different for each iteration through the
foreach.

 

 

####code##############

 

#!/usr/bin/perl

use strict;

use Mail::Sendmail;

 

my $csvfile = 'test.csv';

my $currentline;

open (IN, "<$csvfile") or die "Couldn't open input CSV file: $!";

my @data = sort <IN>;

my $lastline = ' ';

 

foreach $currentline(@data){

        next if $currentline eq $lastline;

        my @split = split(',',$currentline);

foreach my $split (@split){

       &MailPass;

 

}

}

 

close IN;

 

 

sub MailPass{

my $to  = "";

my $username = "";

my $password = "";

my $from  = "[EMAIL PROTECTED]";

my $subject = "Your Login Information";

my %mail = (To            =>                  $to,

                    From        =>                  $from,

                    Subject    =>                  $subject

        Message  =>                 "Your username is $username and your
password is $password",

 

                    

        );

 

sendmail(%mail) or die $Mail::Sendmail::error;

}

 

############end code########################

 

Thanks for the help!

 

Curt

 

Reply via email to