home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / perl / 5872 < prev    next >
Encoding:
Internet Message Format  |  1992-09-11  |  1.6 KB

  1. Path: sparky!uunet!wupost!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: "return <STDIN>;" doesn't work
  5. Message-ID: <1992Sep11.182522.23320@netlabs.com>
  6. Date: 11 Sep 92 18:25:22 GMT
  7. References: <1355@minya.UUCP>
  8. Sender: news@netlabs.com
  9. Organization: NetLabs, Inc.
  10. Lines: 41
  11. Nntp-Posting-Host: scalpel.netlabs.com
  12.  
  13. In article <1355@minya.UUCP> jc@minya.UUCP (John Chambers) writes:
  14. : Well, here's one that probably means I'll learn  just  a  little  more
  15. : about  perl.   I had a routine that was giving nulls when I thought it
  16. : shouldn't, to a caller that looked like:
  17. :     for ($l = &getline()) ...
  18. : I simplified the subroutine to:
  19. : #Example_1:
  20. :     sub getline {
  21. :         return <STDIN>;
  22. :     }
  23. : and it returned a null value.  To find out what the @*&*!$^@ was
  24. : going on, I rewrote it as:
  25. : #Example_2:
  26. :     sub getline {
  27. :         local($x);
  28. :         $x = <STDIN>;
  29. :         return $x;
  30. :     }
  31. : To my surprise, this works! It delivers the data from standard  input,
  32. : one line at a time, and a null at EOF.  I've tried digging through the
  33. : camel book for a possible  explanation  why  Example_2  should  behave
  34. : differently  from  Example_1,  and  I don't understand it at all.  Can
  35. : someone enlighten me?  I suspect that there's something important here
  36. : that I haven't yet learned.
  37.  
  38. Note that the book says "return LIST".  That puts <STDIN> into a list
  39. context, so <STDIN> is going to return The Whole Thing.  You need to say
  40.  
  41.     return scalar <STDIN>;
  42.  
  43. I'm a little surprised that you say it returned a null value.  It
  44. should have returned the last line of the file.  The last line wasn't
  45. blank, was it?
  46.  
  47. Larry
  48.