Help in getting started with Perl

I want to start learning Perl and be able to run programs on my PC.  I am using Windows XP.  I have books on Perl and I have downloaded a version of Perl from www.strawberryperl.com, but I don't know where to go to start putting in commands.  Anything that I try to enter at the C:\ prompt is not recognized.   Can you help me get started?
dwabbottAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
FishMongerConnect With a Mentor Commented:
There was an obvious reason why I used bold highlighting.

c:\testing> is the command line prompt and directory that I was in when executing the script.

type is a Windows command that "types" out the contents of a file.

hello.pl is the filename of the script.

The contents of that file/script is:
#!/usr/bin/perl

# these 2 pragmas should be in every Perl script you write.
use strict;
use warnings;

print "Hello World!\n";

DON'T use a word processor for writing scripts!  Use a text editor, such as notepad.
0
 
ShizzoConnect With a Mentor Commented:
I dont know much about programming but I have heard good things about http://learn.perl.org/
0
 
whosbetterthanmeConnect With a Mentor Commented:
Well, to answer your specific question, in order to run a perl script from the command line (C: prompt), you need to do one of 2 things:

1. At the C:\ prompt, you must first type to whole path to the perl.exe then to the script you are trying to run. Such as:

C:>C:\Perl\bin\perl.exe C:\path\to\my\script.pl

2: You can add Perl to your %PATH, so whenever you type "perl" on the command line, Windows knows where to find it. Such as:

C:\>perl C:\path\to\my\script.pl

To add the path to Perl, you can either on the command line:
set PATH=C:\Perl\bin\;%PATH%

Or go to System Properties and edit Environment variables/Path.

Installing Active Perl will add Perl to the PATH automatically.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
FishMongerCommented:
You didn't say what you entered at the command prompt so it's difficult to say what you did incorrectly.

Were you trying to execute a Perl script or were you trying to execute a Perl "one liner" where the perl commands/code is entered directly at the command prompt instead of from a text file?

If perl was installed correctly, the installation process should have added the location of perl to the path environment var as well as create a .pl filetype association.  However, both of those are install options which could have been unchecked and hence not done.  If that's the case, then you'll want to do that manually.  Once that is complete, you won't need to specify the full path to perl.exe, as suggested by Shizzo, when executing your code.

Creating the file type association:
How to change or select which program starts when you double-click a file in Windows XP

Adding perl to the path:
How To Manage Environment Variables in Windows XP

When writing Perl scripts ALWAYS begin your scripts with the strict and warnings pragmas.
#!/usr/bin/perl

use strict;
use warnings;

Open in new window

Those pragmas will point out lots of common coding mistakes.
0
 
FishMongerCommented:
Here's a good
Perl Beginners' Site.
0
 
dwabbottAuthor Commented:
(I apologize for the delay in answering - for some reason an answer that I wrote did not post.)

Thank you all for your replies - I am still at ground zero, however.  I have downloaded the Strawberry Perl program and then at the C prompt I enter the #!/usr/bin/perl command but it does not recognize the #!.  I get to the C prompt from the start button, All Programs, Strawberry Perl, then the ‘Perl (command line)’ prompt for C:\  -  I tried to follow the suggestions given but I must be doing something wrong.  Where should I be to be able to enter a command starting with ‘#!’ and start in a program, such as hello world?
0
 
FishMongerCommented:
Put your code in a text file.

Write your script
c:\testing>type hello.pl
#!/usr/bin/perl

# these 2 pragmas should be in every Perl script you write.
use strict;
use warnings;

print "Hello World!\n";

Open in new window

Execute the script
c:\testing>hello.pl
Hello World!
0
 
FishMongerCommented:
You can also run code directly from the command line, which is called a perl "one liner".

c:\testing>perl -e "print qq(Hello World!\n)"
Hello World!


However, when first stating out, you should stick with using scripts (code in text files).
0
 
dwabbottAuthor Commented:
Thanks for your reply - I made a file in Word called hello.pl - I went to the C prompt and entered testing>type hello.pl, and get the following:
   'testing' is not recognized as an internal or external command, - - etc.
So it continues to not recognize my inputs at the C prompt.  I notice that at the C prompt I see C:\>, whereas you have simply C:\  -  does this make a difference?
0
 
dwabbottAuthor Commented:
I tried the one-liner  -  
c:\testing>perl -e "print qq(Hello World!\n)"

Same error message.  What about the '>'?  Is this a factor?
0
 
dwabbottAuthor Commented:
FishMonger - Got it!  There were some steps I was not familiar with as I am not well versed in this area.  However, I finally figured out the obvious steps and did the following:
  First - I made a directory named testing
  second, I typed in the little program on notepad and named it C:testing/hello.pl
  third I went to the C:\testing> prompt and typed in 'type hello.pl' and it worked fine.

I knew it was simple!  Thanks very much for your help!
0
 
dwabbottAuthor Commented:
I awarded three contributors, noted on the last comment for each -
  FishMonger  350
  whosbetterthanme  100
  Shizzo 50
I did not award any points to myself
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.