PDA

View Full Version : Learning Perl


unknown333
06-26-2009, 02:26 PM
I'm currently learning Perl and I've learned a lot already. I'm in the advanced stages of learning right now. I must say it's very easy but I still like the language. It's a good language to learn, in my opinion. If you are trying to decide what to learn for a first language, I would recommend Visual Basic, LUA, or Perl. Anyway, I thought I'd share my very first Perl program. It's extremely simple. It's a Hello World program, although it also does a bit more. It looks for an input, and if you type "lol" the program will print "laughing out loud". It's not much worth mentioning but it's good if you'd like to start learning.

#!/usr/bin/perl -w

print "\nHello World ";
$Input = <STDIN>;
chomp($Input);

if($Input eq "lol") {

print "laughing out loud\n";

} # End of if statement

The "#" is what indicates comments in Perl, just as // is used in C++ and some other languages. The first "comment" is to tell the computer where Perl is. This is the most common location. The "$" indicates a scalar variable, in this case a string, which is set to "<STDIN>, which is a filehandle for the input. Since you press "Enter" to submit the input, this also adds a line-ending character (on some OS's, two characters), to indicate the end of the line. "Chomp" takes those off of the end of the string. The "eq" tests if it's equal to, although you could also use "==". This is different from "=" which is used to assign variables. Print simply prints. "\n" skips to the next line.

I know it's not much, but I felt like sharing, and giving a small lesson so people looking to learn a new language but don't know what language can look to see if they have any interest. Personally, I think the language is extremely easy to learn, which isn't usually to my taste, but I find the language is really good. I recommend it for first time programmers.

magcius
06-27-2009, 09:52 AM
I recommend Python for first time programmers.

:P

EDIT: Also, you sig is over the limit, me thinks.

truimagz
06-27-2009, 12:49 PM
Qbasic ftw

unknown333
06-27-2009, 12:50 PM
Qbasic ftw

That was the first language I learned. It's easier than Perl, but it's not really as practical in my opinion.

magcius
06-27-2009, 09:08 PM
In Python:

#/usr/bin/env python
if raw_input("\nHello World ") == "lol":
print "laughing out loud"

unknown333
06-27-2009, 10:30 PM
That sounds really nice. I may decide to learn Python one day.

magcius
06-28-2009, 06:50 AM
:)

http://docs.python.org/tutorial/ (for people who have programmed before)
http://www.greenteapress.com/thinkpython/thinkpython.html (for first-time programmers)

unknown333
06-28-2009, 01:16 PM
Thanks! I'm planning on learning a different language next, but I'll definitely take a look.

megajosh2
07-17-2009, 10:44 AM
Perl is a crock of sh*te, just use Python.

Quadrant-X
08-04-2009, 08:30 PM
see plus plus! see plus plus! (C++)