## Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

• Help others & share knowledge
• Earn cash & points
Solved

# Help in getting started with Perl

Posted on 2012-12-31
454 Views
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?
0
Question by:dwabbott

LVL 1

Assisted Solution

Shizzo earned 50 total points
ID: 38733479
I dont know much about programming but I have heard good things about http://learn.perl.org/
0

LVL 7

Assisted Solution

whosbetterthanme earned 100 total points
ID: 38733550
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

LVL 28

Expert Comment

ID: 38734659
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

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;

Those pragmas will point out lots of common coding mistakes.
0

LVL 28

Expert Comment

ID: 38734665
Here's a good
Perl Beginners' Site.
0

Author Comment

ID: 38759341
(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

LVL 28

Expert Comment

ID: 38759458
Put your code in a text file.

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";

Execute the script
c:\testing>hello.pl
Hello World!
0

LVL 28

Expert Comment

ID: 38759477
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

Author Comment

ID: 38759528
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

Author Comment

ID: 38759555
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

LVL 28

Accepted Solution

FishMonger earned 350 total points
ID: 38759617
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

Author Comment

ID: 38759859
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

Author Closing Comment

ID: 38759906
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
Let’s list some of the technologies that enable smooth teleworking.
The viewer will learn how to create multiple layers to apply various filters and how to delete areas from each layer’s filter.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…