Jay5
11-27-2003, 10:37 PM
I'm finally getting to a point where I've got a good libary of these Perl scripts.
I want to start getting some organization and I need to check my understanding of prototyping and passing parameters to subroutines.
I think what makes most sense is to have routines in specific files and just "require" the ones I need to perform specific tasks for a certain project - noble idea, nothing too crazy I think.
So I've got a main PL with this code in it for example
#!/usr/bin/perl
require "utility.pl";
$variable = &someUtilFunction;
#end of program
and my utility.pl would be
#!/usr/bin/perl
sub someUtilFunction
{
return $someVariable;
} 1;
#end of program
I'm pretty fine with everything above, but problem I have is now I get to a point where I want to feed these subroutines parameters so they do different things and do something based on what I pass in and I stumble onto this area of prototyping which I'm not sure how it fits in.
I'm aware of the convienance operators such as $_ and @_ might make this whole topic mute. But for my purposes I want to be specific, with no short cuts - I get alot of pans on the stove at one time and if I have to leave one thing, move onto another, and then come back to this I don't want to be guessing about what I'm really passing back and forth.
So if I were to want to pass parameters into my utility function above I guess I would make the following changes.
#!/usr/bin/perl
require "utility.pl";
$variable = &someUtilFunction($parameter1, $parameter2);
#end of program
and my utility.pl would then change to
#!/usr/bin/perl
sub someUtilFunction($$)
{
return $someVariable;
} 1;
#end of program
Does "require" take care of the prototyping question and does this make everything nicey, nice for Perl?
I want to start getting some organization and I need to check my understanding of prototyping and passing parameters to subroutines.
I think what makes most sense is to have routines in specific files and just "require" the ones I need to perform specific tasks for a certain project - noble idea, nothing too crazy I think.
So I've got a main PL with this code in it for example
#!/usr/bin/perl
require "utility.pl";
$variable = &someUtilFunction;
#end of program
and my utility.pl would be
#!/usr/bin/perl
sub someUtilFunction
{
return $someVariable;
} 1;
#end of program
I'm pretty fine with everything above, but problem I have is now I get to a point where I want to feed these subroutines parameters so they do different things and do something based on what I pass in and I stumble onto this area of prototyping which I'm not sure how it fits in.
I'm aware of the convienance operators such as $_ and @_ might make this whole topic mute. But for my purposes I want to be specific, with no short cuts - I get alot of pans on the stove at one time and if I have to leave one thing, move onto another, and then come back to this I don't want to be guessing about what I'm really passing back and forth.
So if I were to want to pass parameters into my utility function above I guess I would make the following changes.
#!/usr/bin/perl
require "utility.pl";
$variable = &someUtilFunction($parameter1, $parameter2);
#end of program
and my utility.pl would then change to
#!/usr/bin/perl
sub someUtilFunction($$)
{
return $someVariable;
} 1;
#end of program
Does "require" take care of the prototyping question and does this make everything nicey, nice for Perl?