CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
cannot open file

 



sayal
Novice

Mar 25, 2011, 5:31 AM

Post #1 of 16 (2829 views)
cannot open file Can't Post

Hi,

i try to open a local file on my pc with perl, but it says: "The file could not be opened. Please contact the developer. Invalid argument at C:/xampp/htdocs/test_1.pl line 7. ,"

I have searched many sites and forums what i could have done wrong but i cannot see it. This what i wrote:

<c>

#!C:/Perl/bin/perl.exe

use strict;

our $file = "C:\Documents and Settings\USER\Desktop\project\test.txt";


open (DATA, $file) or die "The file could not be opened. Please contact the developer. $!";
close DATA;

</c>

Thanks in advance!



PS: I get a JavaScript Erro when i try to the Markup toolbar. So i am sorry for my post looking like this!


BillKSmith
Veteran

Mar 25, 2011, 5:54 AM

Post #2 of 16 (2823 views)
Re: [sayal] cannot open file [In reply to] Can't Post

Backslash has a special meaning in double quoted strings. In this case, the easy fix is to use single quotes.
Good Luck,
Bill


sayal
Novice

Mar 25, 2011, 6:46 AM

Post #3 of 16 (2820 views)
Re: [BillKSmith] cannot open file [In reply to] Can't Post

Thanks for the advice!

I tried it, but it still does not work.

I get this message: Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
The file could not be opened. Please contact the developer. No such file or directory at C:/xampp/htdocs/test_1.pl line 7. ,

If you think this is a server error, please contact the webmaster. Error 500 localhost
3/25/2011 3:23:31 PM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1


BillKSmith
Veteran

Mar 25, 2011, 12:11 PM

Post #4 of 16 (2808 views)
Re: [sayal] cannot open file [In reply to] Can't Post

The server probably does not have permission for the file or one of the directories in its path. Can you execute the perl script from a command prompt?



P.S. You should be able to hand code mark-up tags in the forums. The only one you really need is code (use square brackets, not angle).
Good Luck,
Bill


sayal
Novice

Mar 28, 2011, 1:13 AM

Post #5 of 16 (2794 views)
Re: [BillKSmith] cannot open file [In reply to] Can't Post

It is weird. It seems i the perl interpreter i have installed does not work. If i execute perl in a the command prompt by typing "perl -d" it opens normaly, but if i type "h" for example it does not show me anything. What does this mean? I have installed the latest version of Active Perl on a Win XP system.


BillKSmith
Veteran

Mar 28, 2011, 5:56 AM

Post #6 of 16 (2787 views)
Re: [sayal] cannot open file [In reply to] Can't Post

I do not understand what you mean by type "h".

It is a good idea to test your installation.

Verify the version of perl:

At the command prompt type perl -v

Verify execution by running "hello world" several ways:

Keep everything as simple as possible. Work in your home

directory. Create a file called "hello.pl" That file should contain

one line


Code
  

print "hello world\n";



Execute that file by typing


Code
  

perl hello.pl



That should print "hello world" in your command window.

Now test the file type association by typing


Code
  

hello.pl



It should work the same as before.

Now try a method that is not set up by default in version 5.8.8.

again at the command prompt type


Code
  

hello



That may run as before. If not, and you want that feature,

check your help files.

Now add a line to your script.


Code
  

print "hello world\n";

<>;



This change requires you to type <enter> before the script ends.



In windows, find the icon for your hello script and double-click it.

A command window should appear with the words "hello world".

Hit the enter-key and command window should close.

If everything works so far, repeat the experiment with your own script.

If not, you probably do have to reinstall perl.

If your script also works, you are ready to begin debugging

your server problem.
Good Luck,
Bill


rovf
Veteran

Mar 28, 2011, 8:13 AM

Post #7 of 16 (2782 views)
Re: [BillKSmith] cannot open file [In reply to] Can't Post

You should also double the backslashes inside single quotes. I know that this is not always necessary, but it saves you trouble when, for instance, typing UNC pathes.


rovf
Veteran

Mar 28, 2011, 8:14 AM

Post #8 of 16 (2781 views)
Re: [sayal] cannot open file [In reply to] Can't Post

Maybe you introduced a syntax error in your program? Did you try to run it outside xampp?


sayal
Novice

Mar 30, 2011, 2:41 AM

Post #9 of 16 (2751 views)
Re: [sayal] cannot open file [In reply to] Can't Post

Thanks for all the hints! I will take check everything step by step.


sayal
Novice

Mar 30, 2011, 3:24 AM

Post #10 of 16 (2747 views)
Re: [BillKSmith] cannot open file [In reply to] Can't Post

Hi Bilksmith,

i followed your instructions and when i type perl -v at the command prompt something is executed, but the window is closed immediately. Only by typing perl -d the window is not closed. I do not understand why the window is closed in every other case, even if i just type perl.

By the way i have a Windows XP System with the latest version of Active Perl installed. Now i uninstall Active Perl and i will try Strawberry Perl next.


rovf
Veteran

Mar 30, 2011, 3:42 AM

Post #11 of 16 (2746 views)
Re: [sayal] cannot open file [In reply to] Can't Post

I guess you use a normal Windows command Window running cmd.exe, and not some other freeware tool such as Console2?

It's hard to imagine how perl.exe possibly could kill the console windows, though not entirely impossible. However, I would first try to find out whether the "correct" Perl is executed. Can you run it again by specifying the full path to perl.exe explicitly? Also it would help redirecting the stdout to a file, so even if your command windows is closed, you can have a look at the output of perl -v.


sayal
Novice

Mar 30, 2011, 4:28 AM

Post #12 of 16 (2744 views)
Re: [sayal] cannot open file [In reply to] Can't Post

I have installed Strawberry Perl right now and i have tested it. It works. Maybe there went something wrong before with the installation of Active Perl.


FishMonger
Veteran / Moderator

Mar 30, 2011, 8:25 AM

Post #13 of 16 (2740 views)
Re: [sayal] cannot open file [In reply to] Can't Post


Quote
i followed your instructions and when i type perl -v at the command prompt something is executed, but the window is closed immediately.


I'd say you executed it from the 'Run' dialog box and not from the cmd window.


sayal
Novice

Apr 25, 2011, 1:45 AM

Post #14 of 16 (2642 views)
Re: [FishMonger] cannot open file [In reply to] Can't Post

Hi guys,

sorry, but i was wrong. I still have problems with the perl interpreter on my system. I have written several files which run on the apache server i have installed, but none of them run on my local system. I have tried ActiveState and Strawberry Perl, it does not make any difference.

I have tried to verify wether my Perl version was installed properly. When i opened the cmd window and typed perl -v it always displayed the information about the version as expected. Then when i write a test file named hello.pl containing just print "hello world\n"; and try to run this file by typing perl -hello.pl in the cmd window it says: Can't open perl script hello.pl: No such file or directory. I also tried perl ./hello.pl.

I have reinstalled Perl several times. My System is Windows XP SP3.

Any Ideas?


miller
User

Apr 25, 2011, 1:51 AM

Post #15 of 16 (2640 views)
Re: [sayal] cannot open file [In reply to] Can't Post


In Reply To
... and try to run this file by typing perl -hello.pl in the cmd window it says: Can't open perl script hello.pl: No such file or directory.


Did you really try perl -hello.pl or did you try perl hello.pl ?

- Miller


sayal
Novice

Apr 25, 2011, 1:54 AM

Post #16 of 16 (2638 views)
Re: [miller] cannot open file [In reply to] Can't Post

sorry. i tried perl -hello.pl.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives