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

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

perl -e "print \"Hello World\";"

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?

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.

#!C:\Perl\bin\perl.exe  #shebang line

# some code follows
...

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.

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

#!/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

#!/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.

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?

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

but why did it print <br /> as it is?

then what do you wanted to print??? Check your code above.

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?

It printed <br /> because you told it to.

The terminal has no concept of what <br /> is like a web browser does. If you want the html code parsed you have to run the perl script from a web browser and http server.

thanks a lot katharnak.
i want u to help with other problem what i posted as a new thread. i hope u will solve it as earlly as possible for me.

chandrag

I guess you prefer katharnakh's help so I will stop trying to help you with your questions.

Regards
Kevin

I guess you prefer katharnakh's help so I will stop trying to help you with your questions.

Regards
Kevin

sorry kevin, thats not my view. in fact, i didn't observe clearly who posted the last reply. cuz, urs is in 2nd page. i'm really sorry about that. i need ur help. i'm really thankful to u as u've given very clearly described solutions. i hope u will solve my other problem as well.
thank u very much for ur kind co-operation.

chandrag

first run ActivePerl-5.6.1.631-MSWin32-x86(dwnld if dont hav) for perl5.6.1 commands.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.