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

  1. Path: sparky!uunet!world!ora.com!minya!jc
  2. From: jc@minya.UUCP (John Chambers)
  3. Newsgroups: comp.lang.perl
  4. Subject: "return <STDIN>;" doesn't work
  5. Message-ID: <1355@minya.UUCP>
  6. Date: 10 Sep 92 16:12:43 GMT
  7. Lines: 48
  8.  
  9. Well, here's one that probably means I'll learn  just  a  little  more
  10. about  perl.   I had a routine that was giving nulls when I thought it
  11. shouldn't, to a caller that looked like:
  12.  
  13.     for ($l = &getline()) ...
  14.  
  15. I simplified the subroutine to:
  16.  
  17. #Example_1:
  18.     sub getline {
  19.         return <STDIN>;
  20.     }
  21.  
  22. and it returned a null value.  To find out what the @*&*!$^@ was
  23. going on, I rewrote it as:
  24.  
  25. #Example_2:
  26.     sub getline {
  27.         local($x);
  28.         $x = <STDIN>;
  29.         return $x;
  30.     }
  31.  
  32. To my surprise, this works! It delivers the data from standard  input,
  33. one line at a time, and a null at EOF.  I've tried digging through the
  34. camel book for a possible  explanation  why  Example_2  should  behave
  35. differently  from  Example_1,  and  I don't understand it at all.  Can
  36. someone enlighten me?  I suspect that there's something important here
  37. that I haven't yet learned.
  38.  
  39. Oh, yes:
  40.  
  41. | : perl -v
  42. |
  43. | This is perl, version 4.0
  44. | $RCSfile: perl.c,v $$Revision: 4.0.1.4 $$Date: 91/06/10 01:23:07 $
  45. | Patch level: 10
  46. | Copyright (c) 1989, 1990, 1991, Larry Wall
  47. | Perl may be copied only under the terms of either the Artistic License or the
  48. | GNU General Public License, which may be found in the Perl 4.0 source kit.
  49. -- 
  50. All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
  51. 1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc 
  52. --
  53. Pensu tutmonde; agu loke.
  54.