Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!munnari.oz.au!yarra-glen.aaii.oz.au!pem From: pem@yarra-glen.aaii.oz.au (Paul E. Maisano) Newsgroups: comp.lang.perl Subject: when is pass by reference necessary? Message-ID: <1991Mar28.053132.7061@yarra-glen.aaii.oz.au> Date: 28 Mar 91 05:31:32 GMT Organization: Australian Artificial Intelligence Institute Lines: 30 Consider this program: (don't run it unless you need a file called file.dat in the current dir.) #!/usr/bin/perl ($debug = 1, shift) if $ARGV[0] eq '-d'; sub my_open { # called with (file_handle, name) local(*F, $name) = @_; if ($debug) { open(F, ">&STDOUT") || die "can't dup STDOUT: $!\n"; } else { open(F, ">$name") || die "open $name: $!\n"; } } # should this be: &my_open(*X, "file.dat"); &my_open(X, "file.dat"); print X "hello world\n"; close(X); When I wrote this, I intended to pass the file handle as *X but I forgot the *. It still worked so I wondered if I was confused about why I thought the * was necessary. Is it necessary ? --- Paul Maisano, Australian Artificial Intelligence Institute