home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!gumby!destroyer!ubc-cs!unixg.ubc.ca!news
- From: andy@orchid.bdc.ubc.ca (Andrew Dwelly)
- Subject: Re: Arrays of filehandles
- Message-ID: <1992Aug13.164605.10760@unixg.ubc.ca>
- Sender: news@unixg.ubc.ca (Usenet News Maintenance)
- Nntp-Posting-Host: orchid.bdc.ubc.ca
- Organization: University of British Columbia, Vancouver, B.C., Canada
- References: <1992Aug13.145758.14449@news.uit.no>
- Date: Thu, 13 Aug 1992 16:46:05 GMT
- Lines: 51
-
- In article <1992Aug13.145758.14449@news.uit.no> tomg@stud.cs.uit.no (Tom
- Grydeland) writes:
-
- Stuff deleted
-
- > The `@' in `@this[$that]' tells perl that you're refering to an array
- value,
- > i.e the array slice with one value, $this[$that].
- >
- > The first `$' in $this[$that]' tells perl that you're refering to a
- scalar
- > value.
- >
- > thus: @this[$that] == ($this[$that])
- >
- >
-
- Thanks for clearing up my confusion Tom, but surely this means that
- given a file of data "one", the following piece of code should just
- echo it ....
-
- #!/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;
- }
-
- 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).
-
- 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)
-