Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!jarthur!elroy.jpl.nasa.gov!ames!uhccux!munnari.oz.au!frankland-river!pem From: pem@frankland-river.aaii.oz.au (Paul E. Maisano) Newsgroups: comp.lang.perl Subject: Strange behavior with "local" Keywords: local bug Message-ID: <1363@frankland-river.aaii.oz.au> Date: 18 Mar 90 09:36:37 GMT Organization: Australian AI Institute Lines: 42 Maybe I'm missing something but this seems like strange behaviour to me. ----------cut-here--------- #!/usr/bin/perl $buf = "original value"; &buggy($buf); print "buf=$buf\n"; sub buggy { local($buf) = "new value"; print "buf=$buf\n"; $_[0] = $buf; } ----------cut-here--------- Running this produces: buf=new value buf=original value It looks like the global $buf does not get changed. It should, since scalars are passed by reference and the last line in &buggy refers to the global variable. If I change the name of the local variable in &buggy, everything works as expected; the global $buf gets changed. It seems that the value of the $buf variable is being restored before the subroutine is exited. I hope this is a bug, otherwise I have to be very careful about naming my local variables. I'm using perl 3.0 pl15 on a SUN3/60 and sparcstation-1. ------------------ Paul E. Maisano Australian Artificial Intelligence Institute 1 Grattan St. Carlton, Vic. 3053, Australia Ph: +613 663-7922 Fax: +613 663-7937 Email: pem@aaii.oz.au UUCP: {uunet,mcsun,ukc,nttlab}!munnari!aaii.oz.au!pem