general question about programming

Hi. I have a general question about programming. I am wondering when to break things into subroutines and how to recognize when it would be good to do that. Generally I find that I cannot figure this out and my programming becomes very messy and the means to proceed is not clear. I don't know how to think about structuring the program. It seems that for my (very basic) programs that there will be one routine which will call another routine. There is also the problem of passing a value to the second routine. I have learned that this could be done by calling the second routine with arguments from the first routine (this is possible because the second routine is called from within the first routine) and then using shift; to catch the values of the argument.
Still I am not sure about these kinds of issues. Are there any good references or pointers on this?
Thanks.
onyourmarkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
Everyone has their own preferences, but when to create subroutines generally comes down to two factors:

1.  When you want to call the same code multiple times.

2.  When you want to break down a large program into smaller chunks.


For very basic programs, there's generally no need for any subroutines.


To avoid using global variables, you should always parse arguments to your subroutines.
0
onyourmarkAuthor Commented:
Hi. Thank you. What do you mean by "parse arguments to your subroutines."?
0
TintinCommented:
As in

subroutine_name("argument1", "argument2");

0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

onyourmarkAuthor Commented:
Thanks.

How about
subroutine_name argument1, argument2;
0
TintinCommented:
() are almost entirely optional in Perl.

Note that you would need quotes around the arguments if they aren't variables, eg:

subroutine_name "argument1", "argument2";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
onyourmarkAuthor Commented:
THANK YOU.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.