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.
#!/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.