Running Perl or Python scripts

Laestrygon

Solid State Member
Messages
18
Location
USA
I tried to search to see if this was asked or posted already but it gave me something about a database error so I'll ask anyway. I am trying to learn Perl and when I try to run the simple "hello world" that my "absolute beginners guide" had me do I cannot run it. The book said to enter the command prompt and start-program name and it should run but nothing happens. The online tutorial mentions somthing about C:user/bin/path/to/perl or somthing like that. I typed that in exactly how it was written and it did not work either. If I installed strawberry perl in the default directory in win7, and I saved my file helloworld.pl in a folder on the desktop called perlscripts, how would I run this exactly. I am confused about this because the books and the online tutorials dont aim for teaching a complete idiot like me. Please help.
 
"C:user/bin/path/to/perl" is the path to where you installed PERL. Did you install PERL libraries / compiler onto your system yet?

If not, you'll need to do that.

If you did, then you'll need to open command prompt, CD (change directory) to the path where perl is installed, and then you'll either need to place the files you're programming in the same folder as the perl install, or type in the full path (i.e. C:\Users\username\Desktop\project\filename.ext, or whatever it is).

It would also be helpful if you posted a link to the tutorial you're looking at so we can reference it..
 
If you're going to be running perl from the command line fairly often, you will probably want to add it to your PATH.
There are loads of guides for adding entries to your PATH variable so I'll just summarise it as finding perl.exe, copy the file system path from explorer onto the end of the PATH variable in Control Panel\System and Security\System\Advanced System settings and remember that this is a list of values separated by semi-colons.
When you restart the command prompt, you will be able to run perl just by typing 'perl'.
To invoke your perl program, just open command prompt, cd into the directory with your program and type 'perl my-program.pl'.
 
Carnage,

I really cannot remember the tutorial I tried to use because after I was given a book, "Perl programming for the absolute beginner" by Jerry Lee Ford Jr, I took it out of my favorites bar and can no longer find it.

I don't know if I installed libraries or a compiler (I thought scripted languages did not need to be compiled). All I downloaded was strawberry perl and installed into the default directory.

Kmote,

I can already run the perl cmd line by typing perl in the cmd prompt.

I will try these things you guys suggested and get back to you with more questions I am sure.

I just rechecked and made sure that I had the right path. I used cmd prompt Start C:users\path\to\test.pl and it seemed like it ran because I saw a cmd prompt appear and disappear but it happend too fast. I also right clicked the test.pl icon on my desktop and hit run perl script and it did the same thing.

One more thing, I am even having trouble trying to learn one liners in the interactive perl prompt. my book says to write this:

perl -e "print \"hello world!n\";"

I am typing the italicised portion but nothing happens.
 
Last edited by a moderator:
Please don't double post.

You aren't making a lot of sense. If you can invoke the perl interpreter from the command line by typing 'perl' then you are basically there.
1) Open the command prompt.
2) cd into your working directory (the folder on your desktop with your perl scripts)
3) Type 'perl my-program.pl' where my-program.pl is the name of the perl script

If you see "perl is not a recognised command" then perl is not in your path.
If you see "cannot find my-program.pl", then check you have the right path to your program.
If you see no output at all then your program is probably wrong.
 
Sorry for the double post. Like I said in my intro thread, I don't have any real IT experience and I am, as far as I know, doing what you guys and the books are saying but the script wont run. I feel really bad about this because when I tried python the same stuff happened. There is something that I just am not getting I guess and it is making me feel like the biggest idiot in the world because I know that this is a simple thing that I am doing it wrong. I have looked at several tutorials and I have a book to read from and I still don't know what I am doing wrong but I can't explain it clearly enough. I try to follow along but it ain't clicking I guess. Does anyone have a tutorial for actual idiots or children because nothing else seems to be helping me catch on. Sorry for the emo rant ... I am too old to be acting that way :(
 
I feel really bad about this because when I tried python the same stuff happened.
This is off topic, but why did you abandon Python? It is much easier than Perl.

I just rechecked and made sure that I had the right path. I used cmd prompt Start C:users\path\to\test.pl and it seemed like it ran because I saw a cmd prompt appear and disappear but it happend too fast. I also right clicked the test.pl icon on my desktop and hit run perl script and it did the same thing.
Indeed, it does sound like the program did run. If you want the program to run in the same console window from which you are currently typing, then do not use the "Start" command. That will cause the program to run in a new console window that will close when the program has finished running.
 
Last edited:
I was able to get the script to run. Once again I feel like an idiot because all this stuff I posted and the error was simple ... ready? ... I had the path wrong but I am sure you guys already figured that out.

Anyway to answer your question, I left python behind because I got a free book called "Learning Python" but I was told that it is so outdated that the language is not the same anymore (the book covers up to 2.5). I don't know if that is actually true because I failed to do my own research. I did find Python more user friendly and if it is recommended by the people here over Perl then perhaps I should switch back before I get too deep into Perl.

Once again thanks everyone for all the help. Now I know that I need to pay more attention to detail so, in the end I did learn something from this.
 
Back
Top Bottom