Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Sub Routine Ignorance



1:11 am on Jun 6, 2011 (gmt 0)

5+ Year Member

I'm learning(however at a snail's pace). What I understand a sub routine is that it is for re-using code so as to prevent copy/paste/rewriting/etc.,. I've used them in a very limited way to this point but would really like to know a bit more about them. I've done lots of searching but always find explanations that I can't relate to for some reason---I'm not real smart bty.
As an example I have two scripts which basically use the same type of input but am using different input names for the values as they are separate scripts.


#script a #scrip b
$a1="$username"; $b1="$username";
$a2="$userid"; $b2="$userid";
$a3="$submit_time"; $b3="$submit_time";

Seeing as $a1 and $b1 basically hold the same type of value, how would I send both scripts to the same sub without having to use something like:

sub example{
if($a1 eq ""){do something;}
if($b1 eq ""){do something;}

I guess what I'm asking is how does the sub know which script the input is coming from and return the processed values to it? Or, maybe what I'm trying to say is how could I write the sub like this:

sub example{
if($input1 eq ""){do something;}

with $input1 representing either $a1 or $b1 depending on the script that calls it and get the values returned to the appropriate script?

I hope I'm making sense of what I'm asking and not to confusing. I have 3 scripts which will all pretty much use the same input values and am just trying to eliminate all the extra code for doing the same thing.

Software error:

Can't locate /home/deploy/webmasterworld/code_format-v6.lib in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at decode-post-v6.lib line 27, <THREADDAT> line 3.

For help, please send mail to the webmaster (it@imninjas.com), giving this error message and the time and date of the error.