943,965 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 6884
  • Perl RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 17th, 2007
0

problem in running perl script

Expand Post »
hi,

I am new to perl. actually, i'm using perl with SOAP::Lite to access a web server. I wrote some code in a notepad and saved it in c:/perl/eg.
by typing 'perl filename.txt' after changing the directory into c/perl/eg> in command prompt, i am getting the result what i want. it is accessing the web server what i specified in the code and it's giving the output what i need. but i am unable to run pure perl script in command prompt. i typed a simple perl programme to print the elements of an array in a text file and saved it in the same location like earlier. and tried to compile it via command prompt just like earlier. but i can't get any result. and it's saying can't open perl script and there is no such file or directory. i don't understand what the problem is. could u please help with it as early as possible. actually, i have to add some perl code within the earlier code to read a text file and take the elements of that text file and to save them in an array. later those elements should be used one by one in a foreach loop in the code what i've written already. i hope u will solve my doubt as soon as possible.

thank you.
chandra
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chandrag is offline Offline
19 posts
since Jul 2007
Jul 17th, 2007
0

Re: problem in running perl script

You have to use the -e switch to execute code from the command line:

perl -e "print \"Hello World\";"
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jul 18th, 2007
0

Re: problem in running perl script

so, u want me to write the code and save it in a text file and type perl -e and the file name on command line?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chandrag is offline Offline
19 posts
since Jul 2007
Jul 18th, 2007
0

Re: problem in running perl script

Hi,
Quote ...
so, u want me to write the code and save it in a text file and type perl -e and the file name on command line?
Depends,
1. you can write perl code and save it as .pl (for eg. program1.pl) and run.
2. make it executable by inluding shebang* line(in case of UNIX). To run on windows make sure you have set the path to perl interpreter correctly. Then you can run your program like,

>perl program1.pl

The shebang* line, nothing but path to interpreter in your machine, for eg:
in windows( the path may be different on your machine. Depends on where you have installed Perl.
Perl Syntax (Toggle Plain Text)
  1. #!C:\Perl\bin\perl.exe #shebang line
  2.  
  3. # some code follows
  4. ...

You can save the file with .pl extension.

Note: You can use -e option/switch only when you want to work under interpreter mode. i.e, when you want to check some piece of code,
eg. You can check above, KevinADC's post for that... how it goes... or check or check the piece of code.

For big programs you can write it in any editor(for eg. notepad or any suitable editor) and follow the instructions mentioned above.


kath.
Last edited by katharnakh; Jul 18th, 2007 at 10:54 am.
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Jul 18th, 2007
0

Re: problem in running perl script

Quote ...
i typed a simple perl programme to print the elements of an array in a text file and saved it in the same location like earlier. and tried to compile it via command prompt just like earlier. but i can't get any result. and it's saying can't open perl script and there is no such file or directory.

lets see the code you typed and the commands you typed on the command line
Last edited by KevinADC; Jul 18th, 2007 at 2:52 pm.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Jul 19th, 2007
0

Re: problem in running perl script

#!/usr/bin/perl

print "content-type: text/html \n\n"; #HTTP HEADER

# DEFINE AN ARRAY
@coins = ("Quarter","Dime","Nickel");

# PRINT THE ARRAY
print "@coins";
print "<br />";
print @coins;


and i saved it as ex.txt in eg folder in perl folder. and then i opened the command prompt and changed the path to C:/Perl/eg> and then typed perl ex.txt. but its showing it can't open it as there is no such file or directory. but when i saved the same file as "ex.pl" and tried to execute it, the result is

content-type: text/html

Quarter Dime Nickel<br />QuarterDimeNickel
Last edited by chandrag; Jul 19th, 2007 at 8:42 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chandrag is offline Offline
19 posts
since Jul 2007
Jul 19th, 2007
0

Re: problem in running perl script

Click to Expand / Collapse  Quote originally posted by chandrag ...
#!/usr/bin/perl

print "content-type: text/html \n\n"; #HTTP HEADER

# DEFINE AN ARRAY
@coins = ("Quarter","Dime","Nickel");

# PRINT THE ARRAY
print "@coins";
print "<br />";
print @coins;


and i saved it as ex.txt in eg folder in perl folder. and then i opened the command prompt and changed the path to C:/Perl/eg> and then typed perl ex.txt. but its showing it can't open it as there is no such file or directory. but when i saved the same file as "ex.pl" and tried to execute it, the result is

content-type: text/html

Quarter Dime Nickel<br />QuarterDimeNickel
Hi,
Could you please post what message you got when you tried with perl ex.txt . Because i am using perl 5.6.1 on my WinXP machine, and executed your code saving it as .txt file. I had no problem in executing the same.

I even tried in my friend's machine which is Suse Linux, and is running perl, v5.8.8, there also i had no problem in running..

it sounds strange, i doubt you are doing some silly mistake or .....? Please post what you get when you try perl ex.txt . Also which version of perl you are using.

kath.
Last edited by katharnakh; Jul 19th, 2007 at 9:18 am.
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Jul 19th, 2007
0

Re: problem in running perl script

Click to Expand / Collapse  Quote originally posted by katharnakh ...
Hi,
Could you please post what message you got when you tried with perl ex.txt . Because i am using perl 5.6.1 on my WinXP machine, and executed your code saving it as .txt file. I had no problem in executing the same.

I even tried in my friend's machine which is Suse Linux, and is running perl, v5.8.8, there also i had no problem in running..

it sounds strange, i doubt you are doing some silly mistake or .....? Please post what you get when you try perl ex.txt . Also which version of perl you are using.

kath.
hi

i'm getting the below result when i run it.

content-type: text/html

Quarter Dime Nickel<br />QuarterDimeNickel


but why did it print <br /> as it is?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chandrag is offline Offline
19 posts
since Jul 2007
Jul 19th, 2007
0

Re: problem in running perl script

Hi katharnak,

i followed what u specified in ur first reply to me and got the result what i want.

thank u very much.

i will get back to u if i get any problems with perl.

thank u once again

chandrag
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chandrag is offline Offline
19 posts
since Jul 2007
Jul 20th, 2007
0

Re: problem in running perl script

Click to Expand / Collapse  Quote originally posted by chandrag ...
but why did it print <br /> as it is?
then what do you wanted to print??? Check your code above.

kath.
Last edited by katharnakh; Jul 20th, 2007 at 3:36 am.
Reputation Points: 19
Solved Threads: 34
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: gather non-formatted numbers
Next Thread in Perl Forum Timeline: Need help with my script.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC