pem@frankland-river.aaii.oz.au (Paul E. Maisano) (03/07/90)
I guess this is related to my previous posting about passing scalars by reference. Using the type globbing syntax to pass by reference seems IMHO to be kludgy. It would have been nice if you could do: sub add_one { local(*x) = $_[0]; $x += 1; # modify original arg } &add_one($x); # rather than &add_one(*x) I admit that the correct form makes it clear that you are passing x by reference and my version doesn't. It would be great to have some way of simply aliasing variables. [My C programming bias is showing through here.] The reason I starting thinking about this was that I was writing some code in which I had an array element which was being used alot and being modified by subroutine calls; something like: $array[$line0 + $cur_line] = "something"; .... # use that same array element lots &foo($array[$line0 + $cur_line]); arg got modified using $_[0] .... # more use There is no way that I can see of getting a reference to the relevent array element so that I don't have to keep repeating the array expression. I know I could collapse the subscript into a temporary variable but I would rather have a cleaner way of doing things. ( I know, I want too much :-) How about something like: alias(LIST) = LIST; where it is just like a local except that the new variables become references rather than copies. Hey, I just thought of one way: ;-) grep( do { ... # refer to array element as $_ ... }, $array[EXPR] ); Now if I could only name the variable something other than $_ ... ------------------ 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