Basics of Perl!

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

Basics of Perl!
  1. Unread #1 - Aug 9, 2008 at 7:31 PM
  2. MCR__Ftw
    Joined:
    Mar 19, 2007
    Posts:
    1,084
    Referrals:
    0
    Sythe Gold:
    0

    MCR__Ftw Guru
    $5 USD Donor

    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.
     
  3. Unread #2 - Aug 9, 2008 at 7:47 PM
  4. Tezlin
    Joined:
    Apr 9, 2008
    Posts:
    1,780
    Referrals:
    0
    Sythe Gold:
    0

    Tezlin Guru
    Banned

    Basics of Perl!

    Nice. :) But I'm learning C++ at the moment so you're messing with my brain. :(
     
  5. Unread #3 - Aug 9, 2008 at 9:48 PM
  6. Merchant Of Crystal Tears
    Joined:
    Jun 20, 2008
    Posts:
    2,075
    Referrals:
    4
    Sythe Gold:
    0

    Merchant Of Crystal Tears Grand Master
    Banned

    Basics of Perl!

    Well written, 9.5/10.
     
  7. Unread #4 - Aug 9, 2008 at 10:02 PM
  8. SuF
    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

    SuF Legend
    Pirate Retired Global Moderator

    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.
     
  9. Unread #5 - Aug 9, 2008 at 10:17 PM
  10. cp
    Joined:
    Jan 30, 2007
    Posts:
    3,278
    Referrals:
    6
    Sythe Gold:
    0

    cp an cat
    Banned

    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.
     
  11. Unread #6 - Aug 9, 2008 at 11:19 PM
  12. MCR__Ftw
    Joined:
    Mar 19, 2007
    Posts:
    1,084
    Referrals:
    0
    Sythe Gold:
    0

    MCR__Ftw Guru
    $5 USD Donor

    Basics of Perl!

    Thanks CP, I knew I was forgetting some things in my examples, guess my head isn't screwed on tight. :\
     
  13. Unread #7 - Aug 30, 2008 at 3:22 PM
  14. joking
    Joined:
    Nov 9, 2007
    Posts:
    736
    Referrals:
    3
    Sythe Gold:
    0

    joking Apprentice
    Do Not Trade

    Basics of Perl!

    looks good and straight forward. i enjoyed reading this thx
     
  15. Unread #8 - Sep 14, 2008 at 9:56 PM
  16. MCR__Ftw
    Joined:
    Mar 19, 2007
    Posts:
    1,084
    Referrals:
    0
    Sythe Gold:
    0

    MCR__Ftw Guru
    $5 USD Donor

    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.
     
  17. Unread #9 - Sep 16, 2008 at 11:34 PM
  18. klava
    Joined:
    Aug 7, 2008
    Posts:
    718
    Referrals:
    0
    Sythe Gold:
    0

    klava Apprentice
    Banned

    Basics of Perl!

    Nice guide i like it, im gonna start learning this one.
     
  19. Unread #10 - Sep 20, 2008 at 7:30 PM
  20. Ballin Boi
    Joined:
    Apr 28, 2008
    Posts:
    1,536
    Referrals:
    3
    Sythe Gold:
    0

    Ballin Boi Guru

    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?
     
  21. Unread #11 - Nov 3, 2008 at 4:19 PM
  22. Noob!
    Joined:
    Aug 29, 2008
    Posts:
    322
    Referrals:
    0
    Sythe Gold:
    0

    Noob! Forum Addict
    Banned

    Basics of Perl!

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

Users viewing this thread
1 guest


 
 
Adblock breaks this site