Solved

Help in getting started with Perl

Posted on 2012-12-31
12
453 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
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-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Driver Problem 12 89
Microsoft  Partnership 1 80
Vb script to unzip a files and rename the files 5 90
stamp tool on acrobat 1 39
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Let’s list some of the technologies that enable smooth teleworking. 
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

785 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