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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
prakashk021799Commented:
if (@cambridge = grep /Cambridge/, @course) {
    my $course = "@cambridge";
    <!--Cambridge email subroutine-->
} elsif (@newyork = grep /NewYork/, @course) {
    my $course = "@newyork";
    <!--NewYork email subroutine-->
}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.