
monocle
User
Jun 5, 2000, 4:35 PM
Post #8 of 8
(12920 views)
|
Re: Perl Programmers needed to help with scripts
[In reply to]
|
Can't Post
|
|
Ben, After looking at your script, I think it needs some work. Never fear, this is quite a project you've taken on for your 4th script. This liitle piece of code can be used to delete a certain line from the alias file. You will need to look at the value of the submit button that submitted the form and make sure they want to delete that alias. Then call this snippet of code. It should work. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> # Read in the maillist file, check for the one to be deleted, spit the rest back out to the file $alias_name_to_be_deleted = $FORM{'email_1'}; $alias_email_to_be_deleted = $FORM{'email_1f'}; open(ALIASLIST, "$base/email/$user.info") | | safe_die; @lines = <ALIASLIST>; close (ALIASLIST); open(ALIASLIST, ">$base/email/$user.info") | | safe_die; foreach $line (@lines) { if (!($line =~ /$alias_name_to_be_deleted|$alias_email_to_be_deleted|/i)) { print ALIASLIST $line; } } close (ALIASLIST); </pre><HR></BLOCKQUOTE> As far as the modifying an alias goes. I would suggest, in addition to putting the test boxes with the alias info, you also put hidden fields with the same info. Then you could first compare the values of the text boxes with the values of the hidden fields to see if infact they were modified. Then if they were modified, you can locate the line on the data file using the hidden fields and then replace that line with the values of the text boxes. I believe this snippet of code will do just this. <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> # Read in the maillist file, check for the one to be modified, replace it, spit the rest back out to the file $old_alias_name = $FORM{'hidden_email_1'}; $old_alias_email = $FORM{'hidden_email_1f'}; $new_alias_name = $FORM{'email_1'}; $new_alias_email = $FORM{'email_1f'}; if (($old_alias_name ne $new_alias_name) and ($old_alias_email ne $new_alias_email)) { open(ALIASLIST, "$base/email/$user.info") | | safe_die; @lines = <ALIASLIST>; close (ALIASLIST); open(ALIASLIST, ">$base/email/$user.info") | | safe_die; foreach $line (@lines) { if ($line =~ /$old_alias_name|$old_alias_email|/i) { print ALIASLIST "new_alias_name|new_alias_email|"; } else { print ALIASLIST $line; } } close (ALIASLIST); } </pre><HR></BLOCKQUOTE> I will leave it up to you to integrate these snippets of code into your script. Practice makes perfect. Hope these work for you. BTW, I would never think it rude for some one to ask for help. We all have to learn some how. I am always willing to help when I have the time and the solution. Monocle Hear great techno music by Monocle at http://www.mp3.com/monocle
|