in reply to Problem with sub

sub addbuddy { #add victim to buddy list #open names file open (FILE, "names.txt");

You should always check the value returned by open and take appropriate action. How do you know that the file has been opened successfully?

$list = <FILE>;

This takes the first line from FILE and assigns it to $list. That is probably not what you want to do.

close(DATA); #checks each name foreach $item (@list) {

You don't have a variable called @list. If you were running your program with use strict turned on then Perl would have told you that.

#remove lowercase and spaces from names $item =~ s/ //g; $item = lc ($item);

That doesn't remove lowercase letters from the name. It coverts the name to all lowercase.

} #check if name is in file if ($victim eq "$item") {

There's no need to quote $item here.

} else { #if it does not exits add it open (DATA, ">names.txt");

Once again, you don't check the return code from open. Also you open the file for writing (which removes all of the data in the file) when you probably want to append the data to the end of the file.

print DATA "$victim\n"; Close (DATA);

Perl is case sensitive. That should be close.

} #Notify the terminal print "A Buddy name was added.."; }

Hope that helps.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg