Splitting entries in a list array

I have a script that reads course registration data into a list array thus:-

my @course = $query->param("course");
my $course = "@course";

I then wish to send a one instance of that array by e-mail to one address and another instance to a different address. i.e elements containing the word "Cambridge" should go to cambridge@test.com and elements containing "NewYork" should go to newyork@test.com

currently I use:-

if ( $course =~ /Cambridge/ )
      {
                   <!--Cambridge email subroutine-->
              }

elsif ( $course =~ /NewYork/ )
             {    <!--NewYork email subroutine-->
             
              }

But this sends all the elements in the array to each e-mail address if it contains one of the strings. I need it to send only Cambridge elements to Cambridge and only NewYork elements  to New York

ShiggzAsked:
Who is Participating?
 
prakashk021799Connect With a Mentor Commented:
if (@cambridge = grep /Cambridge/, @course) {
    my $course = "@cambridge";
    <!--Cambridge email subroutine-->
} elsif (@newyork = grep /NewYork/, @course) {
    my $course = "@newyork";
    <!--NewYork email subroutine-->
}

0
 
prakashk021799Commented:
# remove the line
# my $course = "@course";

foreach $course (@course) {
    if ( $course =~ /Cambridge/ )
    {
        <!--Cambridge email subroutine-->
    }
    elsif ( $course =~ /NewYork/ )
     {
        <!--NewYork email subroutine-->
    }
    # etc
}
0
 
ShiggzAuthor Commented:
prakashk

That works except that it sends one e-mail per reference of "Cambridge" or "NewYork". Do you know how I would send two references of "Cambridge" in one e-mail from the one form entry?

Sean
0
 
ShiggzAuthor Commented:
prakashk

That works except that it sends one e-mail per reference of "Cambridge" or "NewYork". Do you know how I would send two references of "Cambridge" in one e-mail from the one form entry?

Sean
0
All Courses

From novice to tech pro — start learning today.