Excerpt of message (sent 4 February 1999) by Emmanuel. M. Decarie: > I wonder how people show in their code how a subroutine is altering > a global variable. Your example is about altering the function argument, not a global. You suppose > myFunc(\@global); > > or > > @global = myFunc(\@global); I perfer the first. Fewer keystrokes, and clean enough. The second will copy around all return values, if I read it right (less efficient). > I'm always a little bit worried by what we call in French "effet de > bord" (sorry can't find a translation) "Side effect", quite literally. > at the moment is that when you pass by reference an array or a hash, > there is nothing to show in the params that the function have the > right to make changes to the original. Yes, perl ist not the strictest of languages. In your example, it is quite obvious (from the \) that myFunc _can_ change the variable you pass in. It would be nice to document if it _will_. Using prototypes, you can write functions that implicitly take a reference, without a hint in the calling code. Many of our beloved builtins do this, and indeed change one of their arguments, e.g., chop, splice, push, shift, read, s///. That's fine; you passed the variable explicitly. But if these aren't given enough parameters, they work on $_, @_, or @ARGV (!!). Now that's what I call changing globals. I avoid this in any subroutine I write. Yes, in Ada you can be more specific. Even C++ (and now ANSI C) has the "const" modifier. Perl isn't rigorous. > Is there something similar in Perl ? You could specify it in POD :-) Christian Brechbuehler Communication Technology Laboratory, Image Science Group Swiss Federal Institute of Technology (ETH), Zurich ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch