
dannyb_16
Novice
Oct 1, 2013, 2:08 PM
Post #1 of 4
(2579 views)
|
Searching a text file
|
Can't Post
|
|
I am creating a script which is meant to search a text file for a specific text string which has been entered by a user. #!/usr/bin/perl print "What is your username?\n"; chomp($username = <STDIN>); my $filename = "usernames.txt"; open FILE, "<$filename" || die "Cannot open file\n"; while($line =~ <FILE>) { if ($line =~ m/$username/) { print "That username exists\n"; } }; ************************** Contents of the text file: Username: dannyb_16 Username: carl_45 ************************* The script compiles successfully however, if i enter the username dannyb_16 for instance, it will not print the desired output. All i can assume is that i have made an error which is preventing the file from being searched. Is anyone able to see a problem with this? Regards
|