Path: utzoo!news-server.csri.toronto.edu!rutgers!gatech!ukma!hsdndev!think.com!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!relay.nswc.navy.mil!zogwarg!anneb From: anneb@zogwarg.etl.army.mil (Anne Brink) Newsgroups: comp.lang.perl Subject: Of scoping of local variables and parameters Keywords: what's going on here? Message-ID: <573@zogwarg.etl.army.mil> Date: 12 Mar 91 18:32:17 GMT Distribution: usa Organization: Engineer Topographic Labs, Ft. Belvoir, VA Lines: 58 Apologies if this has been gone over recently, news here just went through another "sporadic delivery" phase. Am I missing some concept about perl scoping here? This behavior seems strange to me: When I invoke { $answer = "Block of text"; &mysubroutine($answer); } and have defined later on: sub mysubroutine { local ($answer, $othervariablename); local ($nam) = @_; print "Parameter passed = $nam.\n"; } I get as output: Parameter passed = . But when I switch the local() declarations, like so: sub mysubroutine { local ($nam) = @_; local ($answer, $othervariablename); print "Parameter passed = $nam.\n"; } I get instead: Parameter passed = Block of text. It looks a lot like I'm tromping on the scope of variable $answer somehow. Changing local ($answer) to local ($anythingelse) in mysubroutine unsuprisingly produces the second result. I wouldn't have expected the parameter's name to have any relevance inside my subroutine, because it's been assigned to @_, or so I understand. (Yes, I know I probably should have the assignment to @_ before the other variable declarations. My editor must have moved them when I wasn't looking.(-:) I'm using 3.0pl44 on SunOS 4.1 on a Sun 3, compiled with gcc 1.37.1 I looked through my camel book and the FAQ, and could not find an appropriate enlightening passage. I'd appreciate any eplanations someone can send my way. E-mail answers would be preferred. Thanks in advance, -Anne Brink -- ############################################################################### Anne Brink # U.S. Army Engineer Topographic Labs anneb@etl.army.mil # Ft. Belvoir, VA (USA) ###############################################################################