Guest_imported
New member
- Jan 1, 1970
- 0
I needed a perl thing that read the number of lines in a text file and printed them on the screen. I asked on a board and was given this code:
open(FILE, "<file.txt" or die 'couldn't open file.txt';
@lines = <FILE>;
close(FILE);
print "The number of lines in file.txt is: $#lines";
That, with the shebang line #!/usr/bin/perl in the beginning, didn't work (gave a 500 error). I know the shebang is correct, the permissions were set correctly, file.txt existed, so what am I doing wrong? Is there something wrong with the code I was given, or do I need to add something more to the code for it to be a complete perl program?
open(FILE, "<file.txt" or die 'couldn't open file.txt';
@lines = <FILE>;
close(FILE);
print "The number of lines in file.txt is: $#lines";
That, with the shebang line #!/usr/bin/perl in the beginning, didn't work (gave a 500 error). I know the shebang is correct, the permissions were set correctly, file.txt existed, so what am I doing wrong? Is there something wrong with the code I was given, or do I need to add something more to the code for it to be a complete perl program?