CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
regex help plz

 



ACtheMadScripter
Deleted

Sep 19, 2000, 6:43 AM

Post #1 of 2 (427 views)
regex help plz Can't Post

Im trying to read a file and add a imputed line if the line is not matched in the file. If the line is matched then the program runs error routine..the end user is only allowed to enter a name, the program does the rest. This is what i have but its matches funny and i cant seem to get what i need.

code:
sub addappend {

&parse;
if ($formdata{'addname'} =~ /\W|\s/) { &error1; }
else {
open(MABLE, "</home/andy/cgi-bin/alias.txt")&#0124; &#0124;&error;
@MABLE = <MABLE>;
close(MABLE);
foreach $name(@MABLE) {
if ($name =~ /($formdata{'addname'}\@$MABLE\[1\])/) { &error2; }
}
open(MABLE, ">>/home/andy/cgi-bin/alias.txt")&#0124; &#0124;&error;
print MABLE "$formdata{'addname'}\@$MABLE[1]\n";
close(MABLE);
open (VIRT, ">>/etc/mail/virtusertable")&#0124; &#0124;&error;
print VIRT "$formdata{'addname'}\@$MABLE[1] $user\n";
close(VIRT);
&hello;
}
}
The File i access looks like this.
andy
thepunk.com
andy@thepunk.com
sales@thepunk.com
webmaster@thepunk.com
info@thepunk.com

the input is one name like: andy or services.

Please Help the Mad!



------------------
AC the Mad Scripter
Script long and prosper!


japhy
Enthusiast

Sep 24, 2000, 5:48 PM

Post #2 of 2 (427 views)
Re: regex help plz [In reply to] Can't Post

Try the following:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


if ($formdata{addname} =~ /\W/) { error1() }
else {
open LIST, "+>>/path/to/alias.txt" or error();
seek LIST, 0, 0; # go to beginning
while (<LIST> ) {
error2() if /$formdata{addname}\@$MABLE[1]/o;
}
print LIST "new data here...\n";
close LIST;
}
</pre><HR></BLOCKQUOTE>

Your main problem was you backslashed the [ and ] in the array element $MABLE[1].

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives