I am trying to populate a textarea with text. The text will be comments a user has made. It will be loaded from a file called comments.txt
The file template is:
username1
commentscomments
commentscomments
username2
commentscommentscome
comchefhjshfhhfjdjdj
dfhfhjdijedhdjdjdjdj
username3
februgusyfvretgtyef
I also have a file called accounts.txt which stores the usernames.
My current code just writes the entire comments.txt file to the textarea
my $username=(param('username'));
open my $FHIN, '<', "comments.txt" || die "$!";
my @fhin = <$FHIN>;
print textarea(-name=>"CommentArea",-default=>"@fhin",-rows=>10,-columns=>60);
I was thinking should I have a sub that returns an array of strings that are the comments of the user? And how should I structure it should I have a loop of the comment file that checks if each line eq the username and if it does it prints each line until it comes to another line that matches a line on the accounts.txt
Basically the textarea should only show:
commentscommentscome
comchefhjshfhhfjdjdj
dfhfhjdijedhdjdjdjdj
if username2 is the user thats logged on.
Any help is appreciated!
ornot||in youropen, as you'll not trap errors using the latter as written, since it's parsed asopen(my $FHIN, '<', 'comments.txt');