Hello. I have a severe problem with open(). Here is my actual code.

#!/usr/bin/perl
	$file = '/testerpage.php';		# Name the file
	open(INFO, $file);		# Open the file
	@lines = <INFO>;		# Read it into an array
	close(INFO);			# Close the file
	print @lines;			# Print the array
<>;

I copied exactly from a website, but renamed the file to one that exists.

Some specs:

  • Windows 7 Ultimate 64 bit
  • Latest version of Notepad++
  • Perl 5
  • Opened it by double clicking

Thanks for the help, Glut.

Works on Linux with a known file, running it from a shell. Change the open statement to

open(INFO, $file) || die "No such file '$file':";              # Open the file

Also run it from a command line; you should see the errors:

perl -w myscript.pl

Finally, double-clicking it mayn't give perl a place to send the output.

Works on Linux with a known file, running it from a shell. Change the open statement to

open(INFO, $file) || die "No such file '$file':";              # Open the file

Also run it from a command line; you should see the errors:

perl -w myscript.pl

Finally, double-clicking it mayn't give perl a place to send the output.

Thank you for teaching me how to open it properly. I get a error now too, thanks to -w.

"readline() on closed filehandle INFO at testperl.pl line 4." Line 4 is @lines = <INFO>; BTW. Oh, and also I added the || die('Error'); and it didn't show anything, so isn't the file that can't be opened. Oh, and also I made a new file as a text file, and it didn't open.

Thanks so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.