|
Subroutines will make
your life so much easier once you start implementing them
into your code. They allow you to not only seperate different
functions from others, but they allow you to call any of the
functions whenever you want. Which means it doesn't matter
what order all your code is in. You can call a subroutine
that's located at the end of your script if you want it to
be the first thing executed!
To
get you familiar with how subroutines look, I have created
some sample code below:
-
#!/usr/bin/perl
-
print "Content-type: text/html\n\n";
- &getIP;
- &display;
-
#Sub GetIP will store your IP in $IP
-
sub GetIP {
-
$IP = $ENV{'REMOTE_ADDR'};
-
}
-
#Sub display will now output your IP
-
sub display {
-
print "Your IP Address: $IP\n";
-
}
Checkout
Feeding Subroutines to learn howto
pass variables to a subroutine from a subroutine call.
|