home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5299 < prev    next >
Encoding:
Text File  |  1992-08-13  |  1.7 KB  |  64 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!gumby!destroyer!ubc-cs!unixg.ubc.ca!news
  3. From: andy@orchid.bdc.ubc.ca (Andrew Dwelly)
  4. Subject: Re: Arrays of filehandles
  5. Message-ID: <1992Aug13.164605.10760@unixg.ubc.ca>
  6. Sender: news@unixg.ubc.ca (Usenet News Maintenance)
  7. Nntp-Posting-Host: orchid.bdc.ubc.ca
  8. Organization: University of British Columbia, Vancouver, B.C., Canada
  9. References: <1992Aug13.145758.14449@news.uit.no>
  10. Date: Thu, 13 Aug 1992 16:46:05 GMT
  11. Lines: 51
  12.  
  13. In article <1992Aug13.145758.14449@news.uit.no> tomg@stud.cs.uit.no (Tom  
  14. Grydeland) writes:
  15.  
  16. Stuff deleted
  17.  
  18. > The `@' in `@this[$that]' tells perl that you're refering to an array  
  19. value,
  20. > i.e the array slice with one value, $this[$that].
  21. > The first `$' in $this[$that]' tells perl that you're refering to a  
  22. scalar
  23. > value.
  24. > thus:   @this[$that] == ($this[$that])
  25.  
  26. Thanks for clearing up my confusion Tom, but surely this means that 
  27. given a file of data "one", the following piece of code should just
  28. echo it ....
  29.  
  30. #!/local/bin/perl
  31.  
  32. open($a[0],"<one");
  33. while (<$a[0]>)
  34. {
  35.     print;
  36. }
  37.  
  38. Which fails to work.
  39. whereas, in perl 4.035 under SunOS 4.1.2, the best I've been able to
  40. come up with is ....
  41.  
  42. #!/local/bin/perl
  43.  
  44. open(scalar($a[0]),"<one");
  45. $foobar = $a[0];
  46. while (<$foobar>)
  47. {
  48.     print;
  49. }
  50.  
  51. That is, not only must the array be made explicitly scalar during the  
  52. assignment of the file handle, but also it must be assigned to
  53. an ordinary scalar before use in angle brackets (I suspect this is because 
  54. perl defines <scalar($a[0])> as a syntactic no-no).
  55.  
  56. The second version works, but is rather inelegant. Is there any way it can  
  57. be improved to remove the superfluous $foobar ?
  58.  
  59. Andy Dwelly (andy@bcu.ubc.ca)
  60.