problem in running perl script

Reply

Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

problem in running perl script

 
0
  #1
Jul 17th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: problem in running perl script

 
0
  #2
Jul 17th, 2007
You have to use the -e switch to execute code from the command line:

perl -e "print \"Hello World\";"
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

 
0
  #3
Jul 18th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: problem in running perl script

 
0
  #4
Jul 18th, 2007
Hi,
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.
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: problem in running perl script

 
0
  #5
Jul 18th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

 
0
  #6
Jul 19th, 2007
#!/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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: problem in running perl script

 
0
  #7
Jul 19th, 2007
Originally Posted by chandrag View Post
#!/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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

 
0
  #8
Jul 19th, 2007
Originally Posted by katharnakh View Post
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

 
0
  #9
Jul 19th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: problem in running perl script

 
0
  #10
Jul 20th, 2007
Originally Posted by chandrag View Post
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC