May 17, 2013, 6:21 AM
You have several errors. The most serious is that you cannot store a list of names in a scalar variable ($name).
Re: [dsaliba] cannot pass contents of a variable from a sub to the main program
As your subroutine reads each name, it overwrites the previous one and prints the current one. When it comes to the end of the file, it sets $name to undef and returns.
Your main program only tries to compare the entry with one name (it does not even have that), not all of them
The subroutine should store all the names as keys of a hash and return the hash. The main program could them test if the name exists in the hash.
UPDATE: Add more comments.
You should always use the pragmas 'use strict' and 'use warnings'. Fix all the errors that they report.
Use the three argument form of open (Refer: perldoc -f open). Also use a lexical filehandle. (my $WORDSLIST rather than the bareword WORDSLIST)
Add the special variable $! (refer: perldoc perlvar) to the error message on open.
It is a good idea to put all your file input in a subroutine. Why not do the same for terminal input? In this case consider using IO::Prompt::Tiny from CPAN.
(This post was edited by BillKSmith on May 17, 2013, 7:12 AM)