954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

open Function not Working

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.

glut
Light Poster
42 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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.

Fest3er
Posting Whiz in Training
242 posts since Aug 2007
Reputation Points: 51
Solved Threads: 35
 

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 = ; 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.

glut
Light Poster
42 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: