Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!munnari.oz.au!frankland-river!pem From: pem@frankland-river.aaii.oz.au (Paul E. Maisano) Newsgroups: comp.lang.perl Subject: Re: Operations on filehandles Summary: Solution does not seem to work. Message-ID: <1041@frankland-river.aaii.oz.au> Date: 9 Feb 90 00:01:53 GMT References: <1004@frankland-river.aaii.oz.au> <7020@jpl-devvax.JPL.NASA.GOV> Organization: Australian AI Institute Lines: 47 In article <7020@jpl-devvax.JPL.NASA.GOV>, lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: > > I believe you can do a local on a name using the type globbing syntax: > > sub foo { > local(*FILE); > > open(FILE,'foo'); > etc. > > I haven't exercised it heavily, but the code is supposedly there to create > a new name if you aren't assigning another name to *FILE. Just as normal > variables created with a null value when you don't assign something to them. This pretty much what I was looking for. It's neater than generating unique filehandle names by hand, but I can't seem to get it to work in a test program. I end up getting a segmentation fault. #!/usr/bin/perl # This is just an otherwise useless program to test recursive opens. sub read_lines { local($name, $n) = @_; local($i); local(*F); open(F, $name) || die "$name: $!\n"; for ($i = 0; $i < $n; $i++) { $_ = ; print("$i ($n): ", $_) || warn("print failed: $!\n"); if ($i == 2 && $n <= 10) { &read_lines($name, $n+5); } } close(F); print "finished $n\n"; } &read_lines("/etc/passwd", 5); exit 0; Generating unique names for filehandles does work, though (as I expected). ------------------ 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