Hello guys:
Im a perl beginner (self taught) and Im unable to get elements from an array.
Here is my situation step by step:
1) A list of emails is submitted, (one email per line), through the texarea of a form named "Email_List " to a script that will check email sintax, etc
List follows: (some emails have wrong syntax on purpose).
ben_wade@gmail. com
benwade@yuma.co m
wade.ben@yuma.c om
ben1981@yahoo.c o.uk
@yuma
yuma
ben_wade.com
benwade1951@yum a.usa.com
@
ben wade
ben.wade.1951@u sa.org
be@wade_org
ben@wade.org
wade.ben@yuma.c om
ben1981@yahoo.c o.uk
wade@cmzad.ll
ben_w@ned.dex
wadeb@rediff.co m
george@gmail.vo m
2) The script that processes this input reads like this:
3) The above foreach loop treats the entire list in $Email_List which is passed to @emails as a single string, what I needed was a neat sorted list of emails printed to the browser one email per line. But I got a single big chunk of emails instead.
4) So I added a split function as follows:
5) This added a space between each character of every email, so I added a space in the split function like this:
5) This didnt make my foreach loop present one email per line neatly sorted either. It broke the big chunk of emails into two smaller chunks of emails. So I thought pehaps I needed to add a carriage return to the spilt function like this:
6) I can tell this last attempt is flat wrong because it gives me an error.
My question is: How can I obtain a sorted list of emails, one per line, from the scalar $Email_List
Thanx beforehand
VirtualWeb
PS: perhaps using cgi-lib.pl is a little antiquated but for this one time only I want to use it
Im a perl beginner (self taught) and Im unable to get elements from an array.
Here is my situation step by step:
1) A list of emails is submitted, (one email per line), through the texarea of a form named "Email_List " to a script that will check email sintax, etc
List follows: (some emails have wrong syntax on purpose).
ben_wade@gmail. com
benwade@yuma.co m
wade.ben@yuma.c om
ben1981@yahoo.c o.uk
@yuma
yuma
ben_wade.com
benwade1951@yum a.usa.com
@
ben wade
ben.wade.1951@u sa.org
be@wade_org
ben@wade.org
wade.ben@yuma.c om
ben1981@yahoo.c o.uk
wade@cmzad.ll
ben_w@ned.dex
wadeb@rediff.co m
george@gmail.vo m
2) The script that processes this input reads like this:
Code:
#!/usr/bin/perl print "Content-type: text/html\n\n"; require "cgi-lib.pl"; &ReadParse; $Email_List = $in{'Email_List'}; $Email_List =~ s/,\s*$//; $Email_List =~ s/^\s+//; $Email_List =~ s/\s+$//; @emails = "$Email_List"; $count = '0'; foreach $submitted_email (sort @emails){ $count++; print qq! <b><font face="arial" size="-1"> $count) $submitted_email</font><br> !; }
4) So I added a split function as follows:
Code:
@emails = split(//, $Email_List);
Code:
@emails = split(/ /, $Email_List);
Code:
@emails = split(/n\/, $Email_List);
My question is: How can I obtain a sorted list of emails, one per line, from the scalar $Email_List
Thanx beforehand
VirtualWeb
PS: perhaps using cgi-lib.pl is a little antiquated but for this one time only I want to use it
Comment