sigmaaa has asked for the wisdom of the Perl Monks concerning the following question:
So I'm opening a .txt file with perl but I want it to check to make sure there is data written to the file and if not to end the program. So far all I can do is get it to run like there is data or run like there isn't any data regardless if there actually is. I've tried just about everything so at this point I've just made two .txt files and left one blank so I can see if wordlist.txt is equal to shit.txt and if they are to kill the program. Still isn't working though, if you could help that would be great!
my $wordlist = 'wordlist.txt'; my $highschool = 'bathroom.txt'; open (LIST, $wordlist) || die "\n Cannot find wordlist.txt \n"; open (lol, $highschool) || die "\n Cannot find bathroom.txt \n"; + print "\n professional site \n"; # After opening the two .txt files I'm checking if they are equal because bathroom.txt is a blank file if ($highschool =~ $LIST) { die "\n No data in wordlist.txt \n"; } else { print "\n All clear \n"};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing if a .txt file contains any data
by RonW (Parson) on Jan 29, 2015 at 22:22 UTC | |
|
Re: Testing if a .txt file contains any data
by sigmaaa (Initiate) on Jan 30, 2015 at 01:33 UTC | |
by locked_user sundialsvc4 (Abbot) on Jan 30, 2015 at 15:08 UTC | |
|
Re: Testing if a .txt file contains any data
by gpapkala (Acolyte) on Jan 29, 2015 at 23:41 UTC | |
by Tux (Canon) on Jan 30, 2015 at 07:01 UTC | |
by sigmaaa (Initiate) on Jan 30, 2015 at 01:10 UTC |