i am running through a series of if/elsif checks on a variable:

if (($add_alias) && ($add_destination) && (!$selection)) {

   if ( $add_alias =~ /[^\w\.\-]/ ) {

   } elsif ( $add_destination !~ /\@/ ) {

   } else {
      open(FILE, ">>$filename");
        print FILE "$add_alias\@$domain\t$add_destination\n";
      close(FILE);
      open(FILE, "$filename");
        @entries = <FILE>;
      close(FILE);
      @entries = sort(@entries);
      open(NEWFILE, ">>$tmpfile");
        foreach $item(@entries) {
          print NEWFILE "$item";
        }
      close(NEWFILE);
      rename($tmpfile, $filename);
   }
}

this script takes input from a user and adds it into $filename after
sorting it and checking to verify that $add_alias has only valid a-z A-Z
0-9 . - and _ characters and $add_destination has an @ symbol included.

i'd now like to insert a test that will check to see if $add_alias is
already included in $filename.

    open(MATCH, $filename);
      while (<MATCH>) {
        @existing = split(/\@/, $_);
        if ( $add_alias eq $existing[0] ) {
          print "That alias already exists!";
          $error=1;
        }
      }
    close(MATCH);

since my if statement is within a while statement, i am not certain how to
include this within my existing checks and ensure that the script will not
execute any of the other actions if a match is found.

Reply via email to