Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:13:59+00:00 2026-06-09T00:13:59+00:00

I was thinking I could do this on my own but I need some

  • 0

I was thinking I could do this on my own but I need some help.

I need to paste a list of email addresses from a local bands mail list into a textarea and process them my Perl script.

The emails are all in a single column; delimited by newlines:

email1@email.com
email2@email.com
email3@email.com
email4@email.com
email5@email.com

I would like to obviously get rid of any whitespace:

$emailgoodintheory =~ s/\s//ig; 

and I am running them through basic validation:

if (Email::Valid->address($emailgoodintheory)) { #yada

I have tried all kinds of ways to get the list into an array.

my $toarray = CGI::param('toarray');
my @toarraya = split /\r?\n/, $toarray;
foreach my $address(@toarraya) {
    print qq~ $address[$arrcnt]<br /> ~:
    $arrcnt++;
}

Above is just to test to see if I was successful. I have no need to print them.
It just loops through, grabs the schedules .txt file and sends each member the band schedule. All that other stuff works but I cannot get the textarea into an array!

So, as you can see, I am pretty lost.

Thank you sir(s), may I have another quick lesson?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:14:01+00:00Added an answer on June 9, 2026 at 12:14 am

    You seem a bit new to Perl, so I will give you a thorough explanation why your code is bad and how you can improve it:

    1 Naming conventions:

    I see that this seems to be symbolic code, but $emailgoodintheory is far less readable than $emailGoodInTheory or $email_good_in_theory. Pick any scheme and stick to it, just don’t write all lowercase.

    I suppose that $emailgoodintheory holds a single email address. Then applying the regex s/\s//g or the transliteration tr/\s// will be enough; space characters are not case sensitive.

    Using a module to validate adresses is a very good idea. 🙂

    2 Perl Data Types

    Perl has three man types of variables:

    Scalars can hold strings, numbers or references. They are denoted by the $ sigil.

    Arrays can hold an ordered sequence of Scalars. They are denoted by the @ sigil.

    Hashes can hold an unordered set of Scalars. Some people tend to know them as dicitonaries. All keys and all values must be Scalars. Hashes are denoted by the % sigil.

    A word on context: When getting a value/element from a hash/array, you have to change the sigil to the data type you want. Usually, we only recover one value (which always is a scalar), so you write $array[$i] or $hash{$key}. This does not follow any references so

     my $arrayref = [1, 2, 3];
     my @array = ($arrayref);
     print @array[0]; 
    

    will not print 123, but ARRAY(0xABCDEF) and give you a warning.

    3 Loops in Perl:

    Your loop syntax is very weird! You can use C-style loops:

    for (my $i = 0; $i < @array; $i++)
    

    where @array gives the length of the array, because we have a scalar context. You could also give $i the range of all possible indices in your array:

    for my $i (0 .. $#array)
    

    where .. is the range operator (in list context) and $#array gives the highest available index of our array. We can also use a foreach-loop:

    foreach my $element (@array)
    

    Note that in Perl, the keywords for and foreach are interchangeable.

    4 What your loop does:

    foreach my $address(@toarraya) {
       print qq~ $address[$arrcnt]<br /> ~:
       $arrcnt++;
    }
    

    Here you put each element of @toarraya into the scalar $address. Then you try to use it as an array (wrong!) and get the index $arrcnt out of it. This does not work; I hope your program died.

    You can use every loop type given above (you don’t need to count manually), but the standard foreach loop will suit you best:

    foreach my $address (@toarraya){
       print "$address<br/>\n";
    }
    

    A note on quoting syntax: while qq~ quoted ~ is absolutely legal, this is the most obfuscated code I have seen today. The standard quote " would suffice, and when using qq, try to use some sort of parenthesis (({[<|) as delimiter.

    5 complete code:

    I assume you wanted to write this:

    my @addressList = split /\r?\n/, CGI::param('toarray');
    
    foreach my $address (@addressList) {
    
       # eliminate white spaces
       $address =~ s/\s//g;
    
       # Test for validity
       unless (Email::Valid->address($address)) {
          # complain, die, you decide
          # I recommend:
          print "<strong>Invalid address »$address«</strong><br/>";
          next;
       }
    
       print "$address<br/>\n";
       # send that email
    }
    

    And never forget to use strict; use warnings; and possibly use utf8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been thinking hard for a long time but couldn't work this out. Consider
I wonder if you could help me with something I've been thinking about. Say
Thinking that the answer to this is pretty obvious but here it goes: When
I have gone through many links on this site and others but I could
I need some help figuring out the best way to proceed with creating a
Here's what I was thinking of this morning: I need to define a lot
Could mapreduce be used to implement a webserver? I'm thinking something like when a
Could somebody explain to me the architecture behind chatroulette? I was thinking about a
Thinking about if we modify the definition of Hamiltonian path as we need to
I need to write some scripts to carry out some tasks on my server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.