Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: problems passing variables between subroutine

by Freezer (Sexton)
on Sep 05, 2012 at 09:36 UTC ( #991796=note: print w/ replies, xml ) Need Help??


in reply to Re: problems passing variables between subroutine
in thread problems passing variables between subroutines

Hi. Your post is useful, thanks. I have gone through points that you have made and added my comments.


retrieve_ESLIM_codes uses the global variable $dbh

Should I be calling the database from within each subroutine, seperately?


retrieve_ESLIM_codes returns @sorted_parameters_A but the return result is not used

I was planning to use this at a future point. Anyway this is a useful reminder thanks.


look_through_file uses and updates $continue_tag, but the result is not used

It is supposed to be used. When the end of file is reached the $continue_tag goes to "FALSE" and this gets passed out of the subroutine from which point the while loop (that makes the subroutine calls in the first place) is broken.


look_through_file populates a local @array_of_lines, but the result is not used

Again. This will be used at a future point. Although I did not correctly build this array (as hinted in your next point).


look_through_file sets a local $entry_no_new, but the result is not used

At one point I did not correctly use this variable. I have removed this incorrect use. However, I don't believe that you are correct in saying that the result is not used. Basically the code is saying that if you get to the next entry number then exit the subroutine.


create_output is passed parameters that have no value

I'm not sure if I understand what you are suggesting here. Is this problem covered in the other posts?


Comment on Re^2: problems passing variables between subroutine
Re^3: problems passing variables between subroutine
by CountZero (Chancellor) on Sep 05, 2012 at 18:40 UTC
    look_through_file uses and updates $continue_tag, but the result is not used

    It is supposed to be used. When the end of file is reached the $continue_tag goes to "FALSE" and this gets passed out of the subroutine from which point the while loop (that makes the subroutine calls in the first place) is broken.

    The value of $continue_tag gets passed out of the subroutine indeed and is immediately discarded because there is no variable to store it in.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
Re^3: problems passing variables between subroutine
by GrandFather (Cardinal) on Sep 05, 2012 at 23:25 UTC

    Avoid "future proofing" code. Almost always we guess wrong about how things are going to go in the future. Leaving decisions until they need to be made generally works better - you have better information to base the decision on. If you guess and decide early it can be much harder to change your mind. You can easily end up with either a lot of work throwing away the code that was never used and rewriting it differently, or accept a sub-optimum solution that becomes hard to understand and maintain.

    With that in mind:

    1. Only pass parameters that are used
    2. Only calculate and return results that are used
    3. Don't use global variables
    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991796]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-04-16 05:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (414 votes), past polls