Solved

Help in getting started with Perl

Posted on 2012-12-31
12
461 Views
Last Modified: 2013-01-09
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
Comment
Question by:dwabbott
[X]
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
  • Learn & ask questions
12 Comments
 
LVL 1

Assisted Solution

by:Shizzo
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

by:whosbetterthanme
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

by:FishMonger
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

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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 28

Expert Comment

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

Author Comment

by:dwabbott
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

by:FishMonger
ID: 38759458
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
 
LVL 28

Expert Comment

by:FishMonger
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

by:dwabbott
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

by:dwabbott
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

by:
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

by:dwabbott
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

by:dwabbott
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

A list of useful business intelligence software.
This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question