Adblock breaks this site

Basics of Perl!

Discussion in 'Archives' started by MCR__Ftw, Aug 9, 2008.

  1. MCR__Ftw

    MCR__Ftw Guru
    $5 USD Donor

    Joined:
    Mar 19, 2007
    Posts:
    1,084
    Referrals:
    0
    Sythe Gold:
    0
    Basics of Perl!

    Well, I'm currently learning Perl too, so it might not be up to par with other Perl guides.

    The basics of Perl!

    Chapters:

    Chapter 1: Starting off


    Chapter 2: Your first Perl program

    Chapter 3: Numbers + Strings


    Chapter 4: Variables

    More coming soon.

    Chapter 1:

    Alright, now you might be asking "what excatly is Perl?". Well since I can't be annoyed typing up something fancy and accurate, I'll get it from Wiki or something.

    http://en.wikipedia.org/wiki/Perl

    Now we'll need to download Perl, which can be found here.

    *Note you'll need Winrar to open it.

    Alright now that everything is downloaded and set up, you might be wondering how to run a script. Well I'll tell you how!

    Code:
    Go to Run>type in CMD and hit enter> type in "c:/perl/bin/scriptname.pl"
    
    Now that we have that squared away I'll show you how to make your first program.

    Chapter 2:

    Now to being open up notepad and at the top put:
    Code:
    #!/usr/bin/perl
    Now hit enter a few times and put in
    Code:
    print 'Hello world!';
    now save it as 1.pl, and save it in C:\Perl\bin

    now run it, and if you're successful you should see Hello world! in your command promp. Great job! Now move on to the next chapter!

    Chapter 3:
    Now numbers in Perl aren't like regular numbers. Instead of having 5,000 or 5 000 in Perl you'll have to put it as 5000.

    Strings are lines of text either with single quotes or double.

    If the line is in double quotes it'll be read and you can put in commands in the quotes such as /n to put it on two different lines.

    If it's in single quotes it'll be read as just / and n nothing special.

    Chapter 4:

    Now we're on our way.

    There are 3 types of variables:

    Scalars
    Arrays
    Hashes

    Scalars:

    Scalars begin with the dollar sign:

    For example if I were to use a scalar I'd put:

    Code:
    my $r = 7;
    You can use different letters and words instead of "r".

    For example I could do this:
    Code:
    my $food = "Tomato";
    my $drink = "Mountain Dew";
    print "My favorite food and drink is $food and $drink;
    It'll show up as this:

    My favorite food and drink is Tomato and Mountain Dew

    Instead of print you may also use say. Print starts new lines automatically, and with say you have to add them manually.

    You can also do math problems with Scalars.

    The symbols are

    Of course you know what the first four symbols are, but what is the last one?
    Well what that does is combines the number, for example if I put 5 . 6 it would equal 56, pretty cool eh?

    Alright I'll wrap it up for now as I'm getting tired of typing :[ I'll edit it with more information over time.
     
  2. Tezlin

    Tezlin Guru
    Banned

    Joined:
    Apr 9, 2008
    Posts:
    1,780
    Referrals:
    0
    Sythe Gold:
    0
    Basics of Perl!

    Nice. :) But I'm learning C++ at the moment so you're messing with my brain. :(
     
  3. Merchant Of Crystal Tears

    Merchant Of Crystal Tears Grand Master
    Banned

    Joined:
    Jun 20, 2008
    Posts:
    2,075
    Referrals:
    4
    Sythe Gold:
    0
    Basics of Perl!

    Well written, 9.5/10.
     
  4. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,211
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Basics of Perl!

    Very basic. How do if, and for statments work?


    What are scalars? Define please. :D


    I think more examples would be nice, to explain what your trying to say. Like give an example with an explination for the single and double quotes and stuff. it makes learning so much easier.
     
  5. cp

    cp an cat
    Banned

    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0
    Basics of Perl!

    Code:
    #!/usr/bin/perl
    Not really necessary unless you're programming on linux/unix or are planning to distribute there.

    Code:
    print "My favorite food and drink is $food and $drink;
    You didn't close the quote; you'll get an error.

    "." doesn't really "combine", more concatenating. In perl,if you use double quotes (") you don't have to concatenate variables, but if you were to use single quotes (') you would need to, or else:
    Code:
    print 'My favorite food and drink is $food and $drink';
    Would return:
    Code:
    lol@lolx:~/Desktop$ perl wtf.pl
    My favorite food and drink is $food and $drink
    meaning you would need to do this:
    Code:
    print 'My favorite food and drink is '.$food.' and '.$drink;
    Pretty basic, but I believe it should help people get going with Perl on their first go.
     
  6. MCR__Ftw

    MCR__Ftw Guru
    $5 USD Donor

    Joined:
    Mar 19, 2007
    Posts:
    1,084
    Referrals:
    0
    Sythe Gold:
    0
    Basics of Perl!

    Thanks CP, I knew I was forgetting some things in my examples, guess my head isn't screwed on tight. :\
     
  7. joking

    joking Apprentice
    Do Not Trade

    Joined:
    Nov 9, 2007
    Posts:
    736
    Referrals:
    3
    Sythe Gold:
    0
    Basics of Perl!

    looks good and straight forward. i enjoyed reading this thx
     
  8. MCR__Ftw

    MCR__Ftw Guru
    $5 USD Donor

    Joined:
    Mar 19, 2007
    Posts:
    1,084
    Referrals:
    0
    Sythe Gold:
    0
    Basics of Perl!

    Yep, you're welcome. If anyone has any questions about this tutorial post them here and I'll try to help the best I can.
     
  9. klava

    klava Apprentice
    Banned

    Joined:
    Aug 7, 2008
    Posts:
    718
    Referrals:
    0
    Sythe Gold:
    0
    Basics of Perl!

    Nice guide i like it, im gonna start learning this one.
     
  10. Ballin Boi

    Ballin Boi Guru

    Joined:
    Apr 28, 2008
    Posts:
    1,536
    Referrals:
    3
    Sythe Gold:
    0
    Basics of Perl!

    As I am trying to learn more languages this will be helpful to me, is it possible for you to add some more?

    I have been looking at this guide and been doing it at the same time (Also using Cp's suggestions).

    So I now want to know what else this can be used for.

    Anyone?
     
  11. Noob!

    Noob! Forum Addict
    Banned

    Joined:
    Aug 29, 2008
    Posts:
    322
    Referrals:
    0
    Sythe Gold:
    0
    Basics of Perl!

    well typed 9.5
     
< Recursion vs Iteration | Weapon "melding" >


 
 
Adblock breaks this site