home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sequent!ogicse!uwm.edu!rpi!usc!elroy.jpl.nasa.gov!ames!sun-barr!news2me.ebay.sun.com!jethro.Corp.Sun.COM!eric.arnold@Sun.COM
- From: eric.arnold@Sun.COM (Eric arnold)
- Newsgroups: comp.lang.perl
- Subject: Re: Arrays of filehandles
- Message-ID: <l8o27cINNocq@jethro.Corp.Sun.COM>
- Date: 14 Aug 92 19:26:36 GMT
- Article-I.D.: jethro.l8o27cINNocq
- References: <1992Aug13.164605.10760@unixg.ubc.ca>
- Reply-To: eric.arnold@Sun.COM
- Distribution: world
- Organization: Sun Microsystems, Inc.
- Lines: 83
- NNTP-Posting-Host: animus.corp.sun.com
-
- In article 10760@unixg.ubc.ca, andy@orchid.bdc.ubc.ca (Andrew Dwelly) writes:
- >In article <1992Aug13.145758.14449@news.uit.no> tomg@stud.cs.uit.no (Tom
- >Grydeland) writes:
- >
- >
- >#!/local/bin/perl
- >
- >open($a[0],"<one");
- >while (<$a[0]>)
- >{
- > print;
- >}
- >
- >Which fails to work.
- >whereas, in perl 4.035 under SunOS 4.1.2, the best I've been able to
- >come up with is ....
- >#!/local/bin/perl
- >
- >open(scalar($a[0]),"<one");
- >$foobar = $a[0];
- >while (<$foobar>)
- >{
- > print;
- >}
- >
-
- This works, without using "scalar" (I added assignment to "@a" because
- it made me feel better, though I assume the above script also implies
- setting "@a"):
-
- $fh_gen = "FH000";
- for ( 1..25 ){ push( @a, $fh_gen++ ) ; }
- open($a[0],"<one");
- $foobar = $a[0];
- while (<$foobar>)
- {
- print;
- }
-
- but I am also puzzled about why this doesn't work:
-
- $fh_gen = "FH000";
- for ( 1..25 ){ push( @a, $fh_gen++ ) ; }
- open($a[0],"<one");
- while (<$a[0]>)
- {
- print;
- }
-
-
-
- >That is, not only must the array be made explicitly scalar during the
- >assignment of the file handle, but also it must be assigned to
- >an ordinary scalar before use in angle brackets (I suspect this is because
- >perl defines <scalar($a[0])> as a syntactic no-no).
-
- "scalar($a[0])" should be the same as "$a[0]", no? Isn't "$a[0]" already
- a scalar? It would seem that the thing that is operating here is only
- that "<$foobar>" works, and "<$a[0]>" doesn't, meaning that you can't
- use an array element inside "<>".
-
- >
- >The second version works, but is rather inelegant. Is there any way it can
- >be improved to remove the superfluous $foobar ?
- >
- >Andy Dwelly (andy@bcu.ubc.ca)
-
-
- This doesn't work either:
-
-
- $a{ "first" } = "FH";
- open($a{first},"<one");
- while (<$a{first}>)
- {
- print;
- }
-
- though if you add the intervening "$foobar", it does work.
-
- -Eric
-
- P.S. I tried this under perl4.019, SunOS4.1.1.
-