in reply to Re: passing of variables
in thread passing of variables

Interesting, this method actually seems easier to read too, I especially like the die's that you have included, I try to error check, but sometimes in perl am not sure how, so thank you again for this wonderful example.

Replies are listed 'Best First'.
Re^3: passing of variables
by John M. Dlugosz (Monsignor) on May 07, 2011 at 01:07 UTC
    I think that's a bit "advanced" or "tricky", and not something you should imitate just now. Get used to dealing with $$name{key} and $name->{key} syntax, as that is present everywhere in modern Perl.

    Using a localized package variable instead of a true lexical variable will lose the benefit of lexical variables: if the function calls another function that uses the package variable, it will see the current local-ized use of it.

      Wow, ok, well, this is where I get a little lost with pointers, I get that way in C also when it gets 'weird' like that (pointers to pointers etc). I would love to see a short example as I can't quite see how I would write it. Also is it a bad thing to have a few 'master hashes' that I control, and pass around and modify? The first time I wrote this, I had almost all global vars and it was terrible! I'm all self taught and all this help sure has opened my eyes to the power and ease, tho at times complex ways to work with perl to be efficient. Thanks again for all the help from all the members, it's very much appreciated!
        Draw a picture, showing a box with a name for a named variable, and containing the root of an arrow that points to another box if it's a pointer. The real value will have the number or whatever in the box, not an arrow to another box.

        Now when you assign something to another variable, you can add that to the diagram and see exactly what level of pointer-ing is involved.

        I don't know if the "master hash" is bad. It depends on the overall design. Moving forward, you might further refactor it.

Re^3: passing of variables
by GotToBTru (Prior) on May 06, 2011 at 20:47 UTC
    The Perl debugger will let you see exactly what is going on. I almost always end up using it when dealing with nested data structures or hashes.