lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/13/90)
It has been pointed out to me that local($foo); causes the value of $foo to be defined. The person who pointed this out felt that it should be undefined. What do you think? Would you rather have to say local($foo,$bar) = ('',''); when you mean that, or local($foo,$bar) = (undef,undef); when you mean that? I can think of arguments for both sides. Larry
oscar@jpl-devvax.JPL.NASA.GOV (Oscar DeMartino) (06/13/90)
In article <8360@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >It has been pointed out to me that > > local($foo); > >causes the value of $foo to be defined. The person who pointed this out >felt that it should be undefined. What do you think? Would you rather >have to say > > local($foo,$bar) = ('',''); > >when you mean that, or > > local($foo,$bar) = (undef,undef); > >when you mean that? I can think of arguments for both sides. > >Larry It is very nice to have it the way it is since it can be used as a simple local flag without having to assign any value to is. if ($value eq "gotit") { . local ($flag); . } . $value = "somethingelse"; . if (defined $flag) { . . } I think you should leave it as is. -- Oscar "Fred" DeMartino - J.P.L. (818) 354-1295 J PPP L 4800 Oak Grove Drive, Pas, CA. 91109 MS: 301-320S J P P L MAYBE: oscar@devvax.JPL.NASA.GOV J J PPP L ARPA: jpl-devvax!oscar@cit-vax JJJ P LLLLL
fpu@taux01.nsc.com (fpu account) (06/13/90)
#In article <8360@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: #>It has been pointed out to me that #> #> local($foo); #> #>causes the value of $foo to be defined. The person who pointed this out #>felt that it should be undefined. What do you think? I vote for separate meanings to separate operators. The local() statement, when not explicitly combined with assignment, should serve to specify the scope of variables and nothing more; an unassigned "local" variable should not be different than an unassigned "global" variable - they should both be undefined. In the following program #local($type); $type = "type1" if ...; $type = "type2" if ...; $type = "type3" if ...; if (defined $type) { . . } Uncommenting local($type) should have no effect on the program other than localising $type. -- Ran -- Reply-To: crehta@taux01.nsc.com (Ran Ever-Hadani) Disclaimer: The above is to be attributed to me only, not to any organization. Apology: Bad English. E-mailed spelling and style corrections are welcome.
jv@mh.nl (Johan Vromans) (06/14/90)
In article <8360@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
It has been pointed out to me that
local($foo);
causes the value of $foo to be defined. ...
I can think of arguments for both sides.
This is a personal opinion, of course. I think that 'local' is
intended to create local variables to prevent clobbering 'global'
variables of the same name. Just like global variables that are
undefined until they are used (i.e. assigned a value), I think that
variables created with 'local' should be undefined until actually used.
I would even like to create all variables with local(...), and have
perl complain about variables referenced but not created explictly.
As an option, of course...
Johan
--
Johan Vromans jv@mh.nl via internet backbones
Multihouse Automatisering bv uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands phone/fax: +31 1820 62944/62500
------------------------ "Arms are made for hugging" -------------------------