Introduction: Learn Perl Easy to Medium

Picture of Learn Perl Easy to Medium

Perl is a text based scripting languge that has it's advantages and disadvantages,this tutorial will give you an overview of the basics and the functions that most scripters (AKA;programers)
would use. LETS GET STARTED! (for windows operators only)
I am assuming that you have worked with a hello world program before or/and worked with a interpeter.

when scripting in perl you have to change your PATH,
but if you dont want to do this, use perl express (shown below).

*note plese rate and comment this instructable

Step 1: The Materials

1.a perl interpeter (google it!)
2.if you want, perl express (google it!)
3.also, if you want , modules (google perl modules for some)
install the modules in the "lib" folder in your perl interpeter's directory

Step 2: Your First Program

okay lets make a simple program,
copy and paste this #!/usr/bin/perl
print "hello world";
that is the simplest program you can make, if you want to add to it a little, type #!/usr/bin/perl
print "hello \n world";
you made your first program! , \n is to make a new line
now lets get a little more advanced

Step 3: Variables

now there are three types of variables,
1.scalers (holds one strip of data) (( $scaler name = value;)
2.arrays (holds multiple strips of data)
((@array name = (values);)
3.hashes %hashname = (value => other value , value => other value #put as many of theses as you want )

Step 4: Getting More Advanced

lets make scripts that print the values of variables,
type these scripts! (you dont have to type the comments , comments are noted with a #)

1. #!/usr/bin/perl
$variablename = 5;
print "$variablename";

2. #!/usr/bin/perl
@arrayname =(value , value2);
#remember , you must refer to arrays as scalars example (the indexe are in order starting at zero

print "$arrayname{0}\n"; #print value
print "$arrayname{1}\n"; #print value2
note:for the code above the { and the } symbols are actully square brackets
3. #!/usr/bin/perl
my %hash = ( v => value , v2 => value2);
print $hash{v};

now lets learn another use for scalers,
type or copy and paste this code

#!/usr/bin/perl
$scalername = <STDIN>;
print $scalername;

type in anything you want
when using command prompt but if you're using perl express,
click on std.input then click on the i/o symbol

now lets find some more uses for variables

Step 5: Another Use and Looping

copy and paste this code

#!/usr/bin/perl
$scalername = <STDIN>;
if ($scalername =~ m/bill clinton/)
{
print "its clinton alright!";
}

okay, you might be asking "what does the if do?"
scroll down and you will see!
>
>
>>
>
>
>>
in the if statment perl behaves the following way,perl asks "does $scalername contain bill clinton?"

here is another function that is also useful

the while function example:
copy and paste this code
#!/usr/bin/perl
$a = 1;
while ($a==1) # == is for numbers only
{
print "a = 1";
}
else { print "a does not equal 1"; }

the next step will talk about boolean functions

Step 6: Boolean

boolean is for numbers only!
heres some functions

== , equals
!= , not equal
< , greater than
> , less than
(*) , multiply note:in multiply theres no ()'s
+ , add

Step 7: Putting It Together

copy and paste this code ,

#!/usr/bin/perl
$operation = <STDIN>;
if ($operation =~ m/multiply/)
{
print "enter a number:\n";
$a = <STDIN>;
print "enter a number to multiply $a:\n";
$b = <STDIN>;
$c = $a * $b;
print "$a multiplyed by $b = $c\n";
}
if ($operation =~ m/add/)
{
print "enter a number:\n";
$a = <STDIN>;
print "enter a number to add to $a:\n";
$b = <STDIN>;
$c = $a + $b;
print "$a added to $b = $c\n";
}

Step 8: Finished!

when you write your own programs you might want to add this function in your code

use warnings;










okay youre done!

Comments

bowmaster (author)2010-01-11

Get Perl for dummies. Way better then this.

GorillazMiko (author)2008-01-01

Wow... looks really complicated.

ellisgeek (author)GorillazMiko2009-10-15

LAME

delphinkid (author)2009-04-12

Which interpreter do you use? Any time I open a script in active perl it closes almost immediately. I can just barely see it say "hello world!".

cris1133 (author)delphinkid2009-04-13

dont open it directly from active perl open the script from a command prompt WITH active perl.If you dont want to do this use perl express.To do it with the prompt change your path to where active perl is.Do this by entering path directory here.Please tell me if this solves your problem if it dosent I will be happy to help.

delphinkid (author)cris11332009-04-16

I opened it with perl express and it worked, thank you for helping!

cris1133 (author)2008-01-02

youthink this is complicated? , try java

cris1133 (author)2008-01-02

what looks complicated ? ,the script in the picture or the tut?