User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 397,851 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,330 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:
Views: 2913 | Replies: 13
Reply
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Help problem in running perl script

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2006
Posts: 591
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 30
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Posting Pro

Re: problem in running perl script

  #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  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

  #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  
Join Date: Jan 2006
Posts: 217
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 19
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: problem in running perl script

  #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 9:54 am.
challenge the limits
Reply With Quote  
Join Date: Mar 2006
Posts: 591
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 30
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Posting Pro

Re: problem in running perl script

  #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 1:52 pm.
Reply With Quote  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

  #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 7:42 am.
Reply With Quote  
Join Date: Jan 2006
Posts: 217
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 19
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: problem in running perl script

  #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 8:18 am.
challenge the limits
Reply With Quote  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

  #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  
Join Date: Jul 2007
Posts: 19
Reputation: chandrag is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
chandrag chandrag is offline Offline
Newbie Poster

Re: problem in running perl script

  #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  
Join Date: Jan 2006
Posts: 217
Reputation: katharnakh is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 19
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: problem in running perl script

  #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 2:36 am.
challenge the limits
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Perl Marketplace
Thread Tools Display Modes

Other Threads in the Perl Forum

All times are GMT -4. The time now is 8:10 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC