Solved

Help in getting started with Perl

Posted on 2012-12-31
12
450 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 28

Expert Comment

by:FishMonger
Comment Utility
Here's a good
Perl Beginners' Site.
0
 

Author Comment

by:dwabbott
Comment Utility
(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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 28

Expert Comment

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how use content aware, what it’s used for, and when to use it over other tools.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now