Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: problems passing variables between subroutine

by GrandFather (Cardinal)
on Sep 05, 2012 at 02:22 UTC ( #991725=note: print w/ replies, xml ) Need Help??


in reply to problems passing variables between subroutines

You completely ignored the last round of advice I gave you so I'd be dumb to offer you more advice wouldn't I? Hey ho, so be it, I'm dumb.

Your actual code shows exactly the problems my previous sample was designed to avoid.

  1. retrieve_ESLIM_codes uses the global variable $dbh
  2. retrieve_ESLIM_codes returns @sorted_parameters_A but the return result is not used
  3. look_through_file uses and updates $continue_tag, but the result is not used
  4. look_through_file populates a local @array_of_lines, but the result is not used
  5. look_through_file sets a local $entry_no_new, but the result is not used
  6. create_output is passed parameters that have no value

and so on, and so on. On top of that:

my $dbh; my $sth_A = $dbh->prepare($sql_command_D) ...

is never going to give a happy result! You have a lot of work to do before your code has any chance of working.

True laziness is hard work


Comment on Re: problems passing variables between subroutine
Download Code
Re^2: problems passing variables between subroutine
by Freezer (Sexton) on Sep 05, 2012 at 09:36 UTC
    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?
      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

      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://991725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-10-25 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (146 votes), past polls