Home | Help Forums | Web Design Tutorials | Free Swishmax Downloads | All Downloads

 

 

Company

Home

Nework Details

Tutorials

SWiSH 2

SWiSHMax

Flash MX

PHP & MySQL

HTML / JScript

Adobe Photoshop

Corel Draw

Gimp

Miscellaneous

Downloads

Templates

Plugins

Fonts

Wallpapers

Free Images

Scripts and Codes

Products

E-Books

SWiSH BB

SWiSH Templates

SWiSH-DB Newsletter
Subscribe to our newsletter : GO
  Partners / Affiliates

   Swish Templates
   SWiSH Climax
   GimpTalk
   Idea Designs
   Sposatoettore
   Try Acai Berry Diet
   Download Free Ringtones
   Swishzone

Manage your site with Flax Article Content Management System
Perl - A Basic Guide for users
Category : HTML / Javascript | Level : Beginner | Language : English
Ask Question | Read Comments | Post tutorial | Previous | Next

Web www.swish-db.com

Inclosed is a small tute i wrote years ago for people who wanted to learn perl from the ground up.
this is tute is for Beginners to start out with
it is in no way a super advanced tute, its just a refrenceTute i wrote
Ali has a small tute explaining the FileHandeling in PHP that i thought
was exellent!!!!

this tute will explain the same thing +more but in
(Practicle Extraction Report Language) { perl }


eg.

open(FILE, ">>$filename");



People always PM me for help in perl everyday
so i wrote this tute just for them,
and i Hope it can help some of you Guy! :-)

I tried uploading this as a txt file but the forum/default settings didnt allow me to so Umm here goes lol!!


#!/usr/bin/perl



print "Content-type: text/html\n\n";



###### LESSONS:
###### BASIC PERL INTRO TO
###### VARIABLES ALSO KNOWN AS SCALARS
###### INTERPOLATION AND STRINGS
###### ARRAYS PUSH AND POP COMMANDS
###### IF, FOR, WHILE, ELSE STATEMENTS
###### STRUCTURES
###### FILE HANDING
###### STRING MATCHING WITH SWITCH AND TRADE SUBSTITUTIONS
###### REGULAR EXPRESSIONS
###### THE HATED SPLIT STATEMENT LOL
###### SPECIAL ARRAYS AND OPERATIONS
###### ENVIROMENTAL VARIABLES
###### SUBROUTINES (similar to function in JS)
###### THE <STDIN> COMMAND



#SECTION 1.
#SCALAR VARIABLES ARE THE SIMPLEST VARIABLES IN HERE ARE SOME EXAMPLES:

$VARIABLE = 25;
print "$VARIABLE <p>";



# SIMPLE RIGHT? THE OUT PUT IS TWENTYFIVE BUT LETS SEE HOW PERL USES
# ARITHMETIC OPERATIONS EXAMPLE:

$EXAMPLE = 2 + 4; # 2 PLUS 4 = 6 AND STORE IN $EXAMPLE
$EXAMPLE = 12 - 6; # 12 MINUS 6 = 6 AND STORE IN $EXAMPLE
$EXAMPLE = 12 / 2; # 12 DIVIDE BY 2 = 6 AND STORE IN $EXAMPLE
$EXAMPLE = 3 * 2; # 3 MULTIPLY 2 = 6 AND STORE IN $EXAMPLE
++$EXAMPLE; #INCREMENT (+1) IN $EXAMPLE
$EXAMPLE++; #SHOW $EXAMPLE AND THEN INCREMENT (+1)
--$EXAMPLE; #DECREMENT (-1) $EXAMPLE AND THEN RETURN
$EXAMPLE--; #SHOW $EXAMPLE AND THEN DECREMENT (-1)

#### WITH THIS EXAMPLE YOUR OUTPUT SHOULD BE 6
#### PLAY AROUND WITH THESE EXAMPLES TO ACTAULLY SEE
#### HOW IT WORKS...

print "$EXAMPLE <p>";


# HERE ARE A FEW EXAMPLES:
# $one = $two;
# Assign $one to $two, value in $two will be transferred to $one

# $one += $two;
# Add $one to $two, if $one is 2 and $two is 3, result wil be 5.

# $one -= $two;
# Subtract $one from $two, if $one is 2 and $two is 3, result will be 1.

# $one .= $two;
# Append $one onto $two, if $one contains 'hello ' and $two contains
# 'world' result will be 'hello world'.






#####################################################

# ARRAYS
# THESE ARE LIKE COMPLEX VARIABLES, ALL THE DO IS
# INSTEAD OF HAVING ONE VARIABLE HAVING 1 VALUE YOU CAN HAVE
# IT SO A VARIABLE HAS MORE OR MANY VALUES AT ONCE
# INSTEAD OF USING THE $ WE UES THE @ INSTEAD.

@COLORS = ('BLUE', 'GREEN', 'RED', 'PINK', 'ORANGE', 'GRAY', '003FFF', 'YELLOW');

# LETS SEE, WE HAVE HERE IS 8 ENTRIES FOR THIS ONE VARAIBLE CORRECT?
# THEY GO BY 1, 2, 3, AND SO ON BUT! PERL INTERPRETS THIS IN A FUNNY WAY
# FOR INSTANCE 1 WOULD = BLUE AND 2 WOULD = GREEN AND 3 WOULD = RED
# THIS IS TRUE BUT FOR ONE THING, PERL STARTS ITS INTERPRET FROM 0 NOT 1
# SO KNOWING THIS BLUE WOULD ACTUALLY BE 0 AND GREEN WOULD BE 1 AND
# 2 WOULD BE RED AND SO ON, UNDERSATND? GOOD LETS PLAY AROUND...
# YOU WOULD CALL THIS AN ARRAY, EACH OF THESE ENTRIES CAN BE ACCESSED LIKE:

print "$COLORS[0] "; # RETURNS BLUE
print "$COLORS[4] "; # RETURNS ORANGE
print "$COLORS[1] "; # RETURNS GREEN
print "$COLORS[7] "; # RETURNS YELLOW
print "$COLORS[2] "; # RETURNS RED
print "<P>";

# OR YOU CAN JUST PRINT OUT THE INTIRE ARRAY
print "@COLORS <p>";

# YOU CAN ALSO USE THE PUSH STATEMENT TO INSERT NEW ITEMS IN TO
# THE END OF THE ARRAY EXAMPLE:

push(@COLORS, 'VIOLET');

print "@COLORS <p>";

# YOU CAN EVEN POP OFF THE LAST ITEM STORED ALSO IN A ARRAY

$VIOLET = pop(@COLORS);


# SCALAR EXAMPLES:

# $A = "@COLORS";
# Stores all items in array into scalar.

# ($A, $B) = ($C, $D);
# $A = $C and $B = $D.

# ($A, $B) = @COLORS;
# $A and $B are first two items.

# ($A, @ARRAY) = @COLORS;
# Stores first item in $A and the rest in @ARRAY.

# (@ARRAY, $A) = @COLORS;
# @ARRAY is @COLORS, $A is undefined.

# $ARRAY_ITEMS = $COLORS;
# Returns the number of the last item in array.


print "@COLORS <p>";

#####################################################
##### ELSE IF STATEMENTS

# THE IF AND ELSE STATEMENTS ARE JUST LIKE WHAT THEY SOUND LIKE
# IF SOMETHING IS TRUE EXICUTE IT, IF ITS NOT OR ELSE DO THIS INSTEAD
# SIMPLE EH? LETS TAKE A QUICK LOOK..

# FIRST OFF LET ME SHOW YOU THE DIFFERENT EQUAL TO NOT EQUAL TO
# STATEMENTS, REMEMBER WHEN DEALING WITH NUMBERS WE USE == ALL THAT
# MEANS IS EQUAL TO AND != MEANS NOT EQUAL TO, BUT IN WORDS OR LETTERS
# WE USE "EQ" FOR EQUAL TO AND "NE" FOR NOT EQUAL TO..
# WE CAN ALSO ASK THE INTERPRETER TO ASK EXAMPLE:

# $A == $B ...... IS $A NUMERICALLY EQUAL TO $B
# $A != $B ...... IS $A NUMERICALLY NOT EQUAL TO $B
# $A EQ $B ...... IS $A EQ TO $B
# $A NE $B ...... IS $A NOT EQUAL TO $B
# ($A && $B) .... IS $A AND $B PRESENT
# ($A || $B) .... IS $A OR $B PRESENT
# !($A) ......... IS $A NOT PRESENT.

# YES IN THIS EXAMPLE IM USING THE LENGHT STATEMENT TO ASK THE
# VARIABLE ARE YOU 8 CHARS LONG


$BEER = 'DRINKING';
if(length($BEER) == 8) {
print "I like $BEER<p>"; }

# HOW TO USE THE ELSE STATEMENTS MULTIPE TIMES WE USE ELSIF
# THEN FOR THE LAST STATEMENT WE JUST USE ELSE.

$BEER = 'DRINKING';
if(length($BEER) == 8) { print "$BEER is good<p>"; }
elsif(length($BEER) == 2) { print "I am 2 letters long<p>"; }
elsif(length($BEER) == 5) { print "I am 5 letters long so print this<p>"; }
elsif(length($BEER) == 3) { print "I am 3 letters long so print this instead<p>"; }
else { print "I meet non of the requirments called out<p>"; }

#### LETS MOVE ON

#####################################################

# CONTROLLING FOREACH

# FOREACH IS USED TO GO THROUGH EACH ITEM IN A ARRAY
# IF AN ARRAY HAS FIVE ITEMS IN IT WE CAN USE FOREACH TO VISIT
# EACH ONE AND PERFORM AN ACTION

@CIGARETTS = ('MARLBORO', 'NEWPORTS', 'BASIC', 'GPC', 'WINSTON');
foreach $CIGARETTS (@CIGARETTS) {
print "My Smokes as follows: currently on $CIGARETTS<br>"; }

# SO LETS GO THROUGH THIS. FIRST WE INITIALIZE THE STATEMENT
# THEN WE DO THE STATEMENT WHILE THE TEST IS TRUE
# THEN WE EXICUTE THE ACTION BEFORE IS LOOPS BACK AGAIN

for($MYNUMBERS = 1; $MYNUMBERS < 11; $MYNUMBERS++) {
print "$MYNUMBERS "; }

# NOT TO HARD HUH, LETS EXAMINE WHAT HAS HAPPENED HERE.
# $MYNUMBERS IS EQUAL TO 1, (((((WHILE)))))) $MYNUMBERS IS LESS THAN
# 11 LOOP THROUGH IT, BEFORE LOOPING THROUGH IT EACH TIME
# INCREMENT $MYNUMBERS.. PRETTY NEAT HUH
# REMEMBER THE WHILE STATEMENT DOES EXACTLY WHAT IT SAYS
# while($MYNUMBERS(1 == 1) { DO THE ACTION }
# SIMPLE??

#####################################################

print "<p>";


##### THE <STDIN> COMMAND
# THIS STANDS FOR (STANDARD INPUT OUTPUT) ALL THIS MEANS IS
# THE SCRIPT WILL ASK FOR INPUT FROM A USER AND THEN THE SCRIPT ASSIGNS
# THE INPUT ENTERED FROM THE USER.

# LETS SEE AN EXAMPLE:

###### $PASSWORD = 'SM4RTSCRIPT';
###### $entered_password = <STDIN>;
###### chop $entered_password;

###### while($PASSWORD ne $entered_password) {
###### print "Wrong password, please try again.";
###### $entered_password = <STDIN>;
###### chop $entered_password; }

# THE REASON WHY THIS EXAMPLE IS COMMENTED OUT OF THIS TUTE
# IS BECAUSE IF IT WAS OPERATIONAL IT WOULD GO ON FOREVER LOL!
# AND THAT WOULD SUCK BUT NOW ATLEAST YOU KNOW WHY
# ANYWAYS, NOTICE THE STATEMENT WITHIN THE WHILE FUNCTION ARE NOT
# EXICUTED, BECAUSE OF THE MISSING PASSWORD NOT PRESENT
# ALL THE CHOP COMMAND DOES IS REMOVE THE USERS
# LAST USERS INPUT

#####################################################

##### FILE CREATION AND HANDLING

$BLAH = "THEPAGE.TXT";

#### HERES WHERE I OPEN THE COMMAND TO MAKE THE PAGE
open (SM4RTSPAGE, ">>$BLAH");


#### WHAT CONTENT I WANT CREATED IN THE NEW PAGE
print SM4RTSPAGE "hello there\n\n";
print SM4RTSPAGE "example: $ENV{'REMOTE_ADDR'} should be your IP\n\n";


#### QUICK NOTE:
#### ANY TIME YOU SEE /n THAT MEANS NEXT LINE TO PRINT
#### AND /r MEANS ALMOST THE SAME THING BUT ITS A CARRAGE RETURN INSTEAD

#### CLOSE THE ARGUMENT
close(SM4RTSPAGE);

#####################################################
# NOW IF YOU GO LOOK IN YOUR CGI-BIN FOLDER THERE SHOULD BE A NEW FILE
# THERE CALLED THEPAGE.TXT WITH THE PRINTED INFO ABOVE LOL!
# EXPLINATION OF THE >> COMMAND IN LINE 2,
# THE JUST MEANS OK >> PRINT THE CONTENTS ONTO THIS PAGE
# IF I JUST USE 1 > INSTEAD OF 2 >> WHAT HAPPENES IS
# THE PAGE GETS UPDATED BY EVERY VIEW OF THIS PAGED BEING OPENED BUT...
# THE PREVIOUS INFORMATION PRINTED IN THE FILE GETS DELETED AND REPLACED
# WITH THIE NEW INFORMATION,
# SO IF U USE 2 >> THE INFORMATION DOESNT GET DELETED BUT INSTEAD GETS UPDATED
# WITHOUT REMOVING ITS PREVIEOUS CONTENT
# THAT WAY U CAN ALWAYS KEEP A LOG OF WHATS GOING ON
#####################################################

# EXPLINATION:

# We use the open() function. The first parameter within the
# brackets is the file handler. We use this to tell Perl what
# name we will use to refer to the file in question from here onwards.
# The second parameter is the name of the file we wish to open,
# let's look at a practical use

# open(FILE, 'AFILE.TXT');
# @lines = <FILE>;
# close(FILE);

# As you can see, we gave the file the handler "FILE".
# The file being opened by Perl is "AFILE.TXT"
# We then read the lines of the file into the array @lines.
# We must enclose the file handler name within < and > for this to work.
# We then close the files, let's have a look at what happened.
# Say AFILE.TXT contains:
# line one
# line two
# line three
# line four
# @lines = ("line one", "line two", "line three", "line four");

# PRINTING TO FILE
# UPDATE FILE
# REMOVE OLD DATA REPLACE WITH NEW

# $SM4RT = 'AFILE.TXT';
# open(FILE_HANDLER, "$SM4RT"); # OPEN FOR READING (input).
# open(FILE_HANDLER, ">$SM4RT"); # OPEN FOR OUTPUT (writing).
# open(FILE_HANDLER, ">>$SM4RT"); # OPEN FOR APPENDING.

# We can open a file just to get input for the script,
# but we may want to write something to that file

# open(FILE, ">>$filename");
# Open file for appending.

# @lines = <FILE>;
# Read lines in array.

# So how do we print to a file?
# Easy, we use an extra parameter in the print statement
# print FILE 'line five';

# LETS SEE WHAT WE CAN DO HERE:

# $FILENAME = 'AFILE.TXT';
# $NUMBER = 0;
# open(FILE, ">>$FILENAME");
# @lines = <FILE>;
# truncate FILE, tell FILE;
# push(@lines, "line 5");

# foreach $line (@lines) { ++$NUMBER; #Increment $NUMBER
# print FILE "$NUMBER - $line";}
# close(FILE);

# You should be able to follow this script. We assign the filename to $FILENAME
# and the number 0 to $NUMBER. We then open the file and read
# each line into the array @lines. We then truncate the file
# with the TRUNCATE statement, this means that we cut the contents
# of the file short, to a specified length, and as we specified
# no length Perl deletes all the contents of the file. Now we need to add
# an extra item into the array, which contains the file's lines.
# We use the push() function that we mentioned in the arrays chapter.
# Now we have out file open for appending, the lines of that file stored in @lines
# and our extra line pushed onto the end of the array. We have the file pointer
# set to the beginning of the file. We use the foreach() function to go through
# each item stored in @lines and call it $line. Each time we go through
# we add one to $NUMBER and then print out "$NUMBER - $line". So we're
# printing out each time, the new value of $NUMBER followed by a dash,
# and then the item of the array that foreach() is currently on,
# what will be printed to the file?

# 1 - line one
# 2 - line two
# 3 - line three
# 4 - line four
# 5 - line five
# |

# The script will print out each array item, which each have a new line
# character on the end, thus the next item will be printed on a new line,
# and the last item also has a new line character so the file pointer
# will be took to the next line before the script finishes, see above

# If we didn't truncate the file after we opened it,
# what would have happened

# line one
# line two
# line three
# line four
# 1 - line one
# 2 - line two
# 3 - line three
# 4 - line four
# 5 - line five


##### STRING MATCHING WITH SWITCH AND TRADE WITH


# A special variable in Perl is the $_ variable.
# This variable is used as the default variable in Perl,
# meaning, if you don't specify a variable to look for a string match in,
# Perl will look for it in $_


# $_ = 'I DRING LOTS OF VODKA';
# if(/VODKA/) { print 'VODKA MATCHES HERE';}

# if(/VODKA/i) { print 'case-insensitive VODKA matches!';}



$variable = "This is our example variable";
print "$variable<p>";

### you can trade any character in your variable for another,
### like here this means "trade every i with a 1". You use
### =~ instead of = when you are altering your variable. The tr
### means "trade", and the / / / seperates what we are trading
### and what we are trading it with.

$variable =~ tr/i/1/;
print "$variable<p>";

### our variable now looks like this:
### Th1s 1s our example var1able

### This is case sensitive, so you can trade lowercase to
### uppercase and vice-versa.

$variable =~ tr/r/R/;
print "$variable<p>";

### our variable now looks like this:
### Th1s 1s ouR example vaR1able

### You can do more than one character at a time using this as
### well. This means trade lowercase e with 3, lowercase
### a with @, and lowercase b with 8.

$variable =~ tr/eab/3@8/;
print "$variable<p>";

### our variable now looks like this:
### Th1s 1s ouR 3x@mpl3 v@R1@8l3

### If you wanted to make the entire variable uppercase or
### lowercase you can do that too. This means trade all lowercase
### letters a through z with uppercase A through Z. We use the
### brackets [] around a-z and A-Z to let the server know we are
### specifying a whole bunch of letters here. The dash means
### simply "through". Without brackets
### it would trade a with A, - with -, and z with Z only.

$variable =~ tr/[a-z]/[A-Z]/;
print "$variable<p>";

### our variable now looks like this:
### TH1S 1S OUR 3X@MPL3 V@R1@8l3

### okay lets start again and do something different..

$variable = "This is our example variable";
print "$variable<p>";

### lets say you wanted to trade more than just character for
### character, lets say you want to trade one word for another.
### instead of tr we use s, which means "switch".

$variable =~ s/example/SMUCKING EXAMPLE/;
print "$variable<p>";

### if you used tr instead of s here, it would trade e with F,
### x with U, a with C, m with K, so on and so forth.

### our variable now looks like this:
### This is our SMUCKING EXAMPLE variable

### The s way of switching is also case sensitive, meaning in the
### above example it would only trade the word example and
### not Example or ExAmPlE. Now that our variable has the word
### example in it in all caps, the above example would not work
### again because the server will only switch the word example
### if it's in all lowercase. To make the switch case
### insensitive, put an i at the end of the whole line
### before the ; like this

$variable =~ s/example/Stupid Stupid Stupid Example/i;
print "$variable<p>";

### our variable now looks like this:
### This is our SMUCKING Stupid Stupid Stupid Example variable


### Also the s way of switching only works on the first time
### the server finds what you want to switch, meaning
### in the above example if you had
### the word example in 3 different places in your variable,
### it is only going to switch the first one it finds. To make
### it switch all of them you put a g (which means "global") at
### the end before the ; like this

$variable =~ s/stupid/lame/ig;
print "$variable<p>";

### our variable now looks like this:
### This is our SMUCKING lame lame lame Example variable

### You can also just remove things you dont
### want in your variable by swtching something with nothing.

$variable =~ s/lame//ig;
print "$variable<p>";

### our variable now looks like this:
### This is our SMUCKING Example variable

### there are a lot of spaces in the variable because i didnt
### specify to remove the spaces, so i can remove extra spaces
### like this, which means switch every 2 spaces with 1 space.
### Of course extra spaces dont really matter because if you
### print it to the page, HTML automatically makes multiple
### spaces just show as one space.

$variable =~ s/ / /ig;
print "$variable<p>";

### our variable now looks like this:
### This is our SMUCKING Example variable


### Just for fun lets remove all the damn spaces

$variable =~ s/ //ig;
print "$variable<p>";

### our variable now looks like this:
### ThisisourSMUCKINGExamplevariable


### Now lets play around a little bit
### this will be part of your lesson
### now since i showed you how variables work
### lets see if you can create your name
### in a hidden variable string
### here is your example with my name
### In this example i will use the variable
### called HIDE...
### this little string means sm4rt_script

#####################################################
#####################################################

$hide = "01H%XE92%B5089E37%6HHHW%%2";
$hide =~ tr/0/s/; $hide =~ tr/1/m/; $hide =~ s/W//ig;
$hide =~ s/B//ig; $hide =~ tr/X/4/; $hide =~ tr/9/r/;
$hide =~ tr/2/t/; $hide =~ tr/5/_/; $hide =~ tr/8/c/;
$hide =~ tr/7/i/; $hide =~ tr/6/p/; $hide =~ s/3//ig;
$hide =~ s/E//ig; $hide =~ s/H//ig; $hide =~ s/%//ig;

print "$hide";

#####################################################

##### REGULAR EXPRESSIONS

#### . # Any single character except a newline
#### ^ # The beginning of the line or string
#### $ # The end of the line or string
#### * # Zero or more of the last character
#### + # One or more of the last character
#### ? # Zero or one of the last character
#### /t.d/ # Will match tod, ted, tad, etc.
#### /^the/ # Will match the at "the" beginning of a sentence.
#### /the$/ # Will match "the" at the end of a sentence.
#### /the*/ # "the" followed by 0 or more of last char (the, thee, theee).
#### /the+/ # "the" followed by 1 or more of last char (thee, theee, theeee).
#### /the?/ # "the" followed by the 0 or 1 of last char (the, thee).
#### /[abc]/ # a, b or c.
#### /[^abc]/ # Not a, b nor c.
#### /[a-z]/ # Anything from a to z.
#### /[0-9]/ # Anything from 0 to 9.
#### /[^a-z]/ # No lower case letters.
#### /[a-zA-Z]/ # Any letter.
#### /[a-z]+/ # Any sequence (1 to infinity) of lower case letters.
#### /right|wrong/ # "right" or "wrong".
#### /(w|p)ant/ # "want" or "pant".
#### /(f|ht)tp/ # "ftp" or "http".
#### /(ab)+/ # "ab" or "abab" or "ababab" etc.

# Remember, when trying to match a special RE character
# you must preceed it with a backslash

#### /$/ # A $ sign.
#### /[/ # A [ sign.
#### /]/ # A ] sign.
#### /./ # A . sign.
#### /$/ # A $ sign.
#### /*/ # A * sign.
#### /|/ # A | sign.
#### /\/ # A backslash.



print "<p>";
#####################################################

#### ASSOCIATIVE ARRAYS

# Unlike list arrays, associative arrays start with a %. They
# are just what they say they are, associative. Look how the
# array declaration is layed out, in groups of two, penny - 1 CENT;
# NICKLE - 5 CENTS; QUARTER - 25 CENTS Each pair is associated with one another
# they are separate array items, yet they are tied to each other
# LETS SEE AN EXAMPLE:

%CASH = ('PENNY', '1 CENT',
'NICKLE', '5 CENTS',
'QUARTER', '25 CENTS',
'DIME', '10 CENTS',
'DOLLAR', 'ITS A BUCK');

print "$CASH{'PENNY'}<br>";
print "$CASH{'NICKLE'}<br>";
print "$CASH{'QUARTER'}<br>";
print "$CASH{'DIME'}<br>";
print "$CASH{'DOLLAR'}<br><P>";

# Look at the top one $CASH{'PENNY'};.
# PENNY is the "key". "1 CENT" is the "value".
# Each key and value are associated with eachother.
# Notice how we use $ instead of % when accessing each value,
# that's because the value is a scalar value, the same as when we
# access an item in a list array.
# We can convert an associative array to a list array,
# and a list array to an associative array.


foreach $CURRENCY (keys %CASH){ print "I HAVE A $CURRENCY<BR>"; }

# Environment variables are readily available to you in your scripts.
# When the script is run Perl collects information about the person using
# the script and stores them in the %env variable.
# this is a perfect example of the print ENV VARS:

foreach $ev (keys %ENV) {
print "<br>$ev is set to $ENV{$ev}"; }

print "<p>";

##################################


######### SPLITS

# Split is an extremely useful function in Perl.
# Like substitution this function uses a regular expression
# and works with the $_ variable unless otherwise specified

# $NAMES = 'JOE|DUANE|SM4RT|JOHN|JACK';
# @ARRAY = split(/|/, $NAMES);
# Which has the same effect as
# @ARRAY = ('JOE', 'DUANE', 'SM4RT', 'JOHN', 'JACK');

# Look at the code and try to understand what is going on. Firstly
# we declare an array that we want the results from th split function
# to be stored in. The split() function uses two parameters. Firsty the
# regular expression at which we want to split, as always contained
# between /../, then a comma, then the name of the scalar variable which
# we want to split. In the example remember that | is a regular expression
# special character, so it must be escaped with a backslash.
# If we have the string stored in the special $_ variable then we can just do:
# @ARRAY = split(/|/);
# As mentioned we can use a regular expression
# $NAMES = 'JOE|DUANE||SM4RT|||JOHN||||JACK';
# @ARRAY = split(/|+/, $NAMES);
# Which has the same effect as:
# @ARRAY = ('JOE', 'DUANE', 'SM4RT', 'JOHN', 'JACK');



# $NAMES = 'JOE|DUANE||SM4RT|||JOHN||||JACK';
# @ARRAY = split(/|/, $NAMES);
# WOULD HAVE THE SAME EFFECT AS:
# @ARRAY = ('JOE', 'DUANE', '', 'SM4RT', '', '', 'JOHN', '', '', '' 'JACK');



# We can split a word into letters, a sentence into words
# and a paragraph into sentences
# @CHARS = split(//, $WORD);
# @WORDS = split(/ /, $SENTANCE);
# @SENTANCES = split(/./, $PARAGRAPH);




#####################################################

########## SUBROUTINES
##### FOR THOSE JAVASCRIPT WRITERS THIS WILL LOOK FARMILIAR

# JUST LIKE JS YOU HAVE THE ABILITY TO USE FUNCTION()
# THE ONLY DIFFERENCE HERE IS PERL USES (SUB) LETS LOOK AT A FEW
# EXAMPLES HERE:

sub SM4RTSCRIPT { print "the sub routine is shown here<BR><BR>"; }

&SM4RTSCRIPT; # <--- ALL THAT DOES IS EXICUTE THE SUB FUNCTION ITSELF

#### PRETTY EASY HUH SEE PERL ISNT THAT HARD IS IT!!


All rights reserved - swish-db.com