You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Perl Tutorial #1 - Hello World! on Fri Feb 11, 2011 4:14 am

The Professor

avatar
Contributor
Loading
I was inspired by Jovan's Perl thread in Zerozaku to learn Perl. Likewise, I've decided to post things I learn about it when I have the chance. This will be the first Perl tutorial! The script I post will have comments throughout so it will explain Perl concepts and elements in style.

First off, you'll need a text editor, personally I prefer Notepad++ over Padre so I'll be providing the download link to it instead of Padre.

- [You must be registered and logged in to see this link.]

Next, paste the code I include in this post to Notepad++ and find the menu item Language, the languages are sorted alphabetically so scroll down 'til you find the P's and that's where the Perl syntax highlighting option can be selected from. After Perl is selected save the file as "hello.pl", minus the quotes of course and run from the directory you saved the file in.

Code:

Code:
# - # is the comment character in Perl, use this to toggle comments in your program. Also note that comments are ignored by the Perl interpreter.

#!/usr/bin/perl #This is something known as a shebang line, used these to associate your Perl program with the Perl bin / interpreter.

print("Who would you like to say hello to? "); #Prints the specified prompt-based text to the Perl console.

$user = <STDIN>; #This is a macro in Perl you use to receive input from the user.

chomp($user); #Removes the newline from the <STDIN> macro so it doesn't cause the Perl interpreter to have trouble validating user input.

#If, Else, ElseIf control structures.

if ($user eq "beeer") { #The keyword eq is used for case-sensitive procedures.
    print "beeer maid? \n"; #\n is an escape character in Perl, it's used to start newlines, similar to the @CRLF macro in AutoIt.
}
elsif ($user eq "Protozoid") {
    print "You hit the jackpot! Protozoid is winrar. ^___^ \n";
}
else { #If none of the blocks above are true (user is not Protozoid or beeer), execute the statement(s) after the else control structure.
    print("hello, " . $user . "!" . "\n") #. is the concatenation operator in Perl. Use it to join strings together.
}

$keep_alive = <STDIN>; #Using this at the end of your Perl scripts makes the interpreter assume that you're still trying to receive user input; use this to keep your Perl programs alive if you don't want the console to close immediately after everything is executed.

I hope you all enjoyed.

Download Link to Perl: [You must be registered and logged in to see this link.]
Download Link to Perl for Windows: [You must be registered and logged in to see this link.]

Note to users: CT is crappy so it isn't letting a certain character I'm trying to post display, I advise you to use this link - [You must be registered and logged in to see this link.] - to get the Perl code I posted here.



Last edited by Protozoid on Fri Feb 11, 2011 7:41 pm; edited 2 times in total

2 Re: Perl Tutorial #1 - Hello World! on Fri Feb 11, 2011 5:23 am

DJ Fresh

avatar
Master
Loading
We should learn how to work other programs before we try Perl right man?

3 Re: Perl Tutorial #1 - Hello World! on Fri Feb 11, 2011 7:40 pm

The Professor

avatar
Contributor
Loading
Death wrote:We should learn how to work other programs before we try Perl right man?

Um, I don't really know. Some say Perl is ideal for a first language while others argue that it's too complex for a first language. My opinion would be that you should learn how to work with easier languages first such as AutoIt and VB before trying to mess with Perl.

4 Re: Perl Tutorial #1 - Hello World! on Fri Feb 11, 2011 10:41 pm

DJ Fresh

avatar
Master
Loading
Protozoid wrote:
Death wrote:We should learn how to work other programs before we try Perl right man?

Um, I don't really know. Some say Perl is ideal for a first language while others argue that it's too complex for a first language. My opinion would be that you should learn how to work with easier languages first such as AutoIt and VB before trying to mess with Perl.
School programming classes

5 Re: Perl Tutorial #1 - Hello World! on Sat Feb 12, 2011 2:11 am

OwenWilson

avatar
Master
Loading
"Strawberry Perl?"
SOUNDS ADORABLE!!!!
Very Happy
Jkjkjkjkjk... Perl is super manly...
I'm not personally interested in it, but nice tutorial.
I think I'll learn other coding languages before Perl.

6 Re: Perl Tutorial #1 - Hello World! on Sat Feb 12, 2011 3:10 pm

The Professor

avatar
Contributor
Loading
OwenWilson wrote:"Strawberry Perl?"
SOUNDS ADORABLE!!!!

Jkjkjkjkjk... Perl is super manly...
I'm not personally interested in it, but nice tutorial.
I think I'll learn other coding languages before Perl.

'bout to say man, 'bout to say...

Perl put hair on my chest the instant I used it.

7 Re: Perl Tutorial #1 - Hello World! on Thu Feb 17, 2011 1:11 am

OwenWilson

avatar
Master
Loading
Protozoid wrote:
OwenWilson wrote:"Strawberry Perl?"
SOUNDS ADORABLE!!!!

Jkjkjkjkjk... Perl is super manly...
I'm not personally interested in it, but nice tutorial.
I think I'll learn other coding languages before Perl.

'bout to say man, 'bout to say...

Perl put hair on my chest the instant I used it.

Perl is sooper manly.
Like, that's why I'm holding off on learning it...
I think it'd be too much to handle.
It's a hunky burlesque of he-man discourse.

Sponsored content


Loading

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum