Perl Tutorial #1

Discussion in 'Code Snippets and Tutorials' started by the_skip, Jul 12, 2007.

  1. the_skip

    the_skip Level IV

    Joined:
    Dec 25, 2006
    Messages:
    2,354
    Likes Received:
    1
    Location:
    Indiana
    Keep in mind I am currently just working on this one. It'll be pretty basic
    So you decided to chose perl
    Perl is great for those who want to learn php since php was based off perl



    Part one Hello World and other intro stuff

    Ok so how do I code perl. Easily enough you can use notepad to code it. after you type your code click file save as select all file types and the name should be x.pl. To run the program open command prompt type cd the directory the perl script is in press enter. now type perl x.pl.(where x is the name of the pl file)
    After you open up notepad put this code in
    Code (Text):
    1. #!/usr/local/bin/perl
    All perl scripts need it it specifies where the perl interpreter is. After you add that type
    Code (Text):
    1.  print 'Hello World' ;
    It wasn't that hard was it. Now lets try something different like accepting user input. Variables do not need to be defined before you have them equal sometime so lets have the variable $name be what the user inputs. Now lets make a whats your name
    Code (Text):
    1. #!/usr/local/bin/perl
    2. #comments come after a #
    3. # asks the user whats there name
    4. print 'What is your name? ' ;
    5. $name = <> ;
    6. print "Hello $name" ;
    7.  
    As you know from before the program put on the command line what is your name. The line $name = <> meant that the variable $name is equal to what the user inputer on the command line.
    NOTE: I am just learning Perl so If I messed something up tell me
     
    jfur_x likes this.
  2. Rebecca

    Rebecca Level II

    Joined:
    Jun 22, 2007
    Messages:
    184
    Likes Received:
    0
    Location:
    Scotland
    This looks good. I always need things to be nice and basic when I start off. I'm going to watch this so I can come back later and try some PERL for myself! :)
    What does php mean?
     
  3. Mat2dong

    Mat2dong Level I

    Joined:
    Jan 27, 2008
    Messages:
    143
    Likes Received:
    0


    I never really got into it...

    I have used PHP a bit...

    This site made with PHPnuke I think:)
     
  4. ricothegreat221

    ricothegreat221 Level II

    Joined:
    May 8, 2009
    Messages:
    302
    Likes Received:
    3
    Hi

    Just a couple of things I want to point out:
    1) Use warnings! Use strict! These are pragmatic modules which will slap you if you do something horribly wrong, which in the end results in better code. So really, each script should start out with:
    Code (Text):
    1.  
    2. #!/usr/bin/perl
    3. #  (Or whatever the path to perl is)
    4.  
    5. use warnings;
    6. use strict;
    7.  
    ----

    PHP is another programming language, aimed primarily at making small websites.