home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!world!ora.com!minya!jc
- From: jc@minya.UUCP (John Chambers)
- Newsgroups: comp.lang.perl
- Subject: "return <STDIN>;" doesn't work
- Message-ID: <1355@minya.UUCP>
- Date: 10 Sep 92 16:12:43 GMT
- Lines: 48
-
- Well, here's one that probably means I'll learn just a little more
- about perl. I had a routine that was giving nulls when I thought it
- shouldn't, to a caller that looked like:
-
- for ($l = &getline()) ...
-
- I simplified the subroutine to:
-
- #Example_1:
- sub getline {
- return <STDIN>;
- }
-
- and it returned a null value. To find out what the @*&*!$^@ was
- going on, I rewrote it as:
-
- #Example_2:
- sub getline {
- local($x);
- $x = <STDIN>;
- return $x;
- }
-
- To my surprise, this works! It delivers the data from standard input,
- one line at a time, and a null at EOF. I've tried digging through the
- camel book for a possible explanation why Example_2 should behave
- differently from Example_1, and I don't understand it at all. Can
- someone enlighten me? I suspect that there's something important here
- that I haven't yet learned.
-
- Oh, yes:
-
- | : perl -v
- |
- | This is perl, version 4.0
- |
- | $RCSfile: perl.c,v $$Revision: 4.0.1.4 $$Date: 91/06/10 01:23:07 $
- | Patch level: 10
- |
- | Copyright (c) 1989, 1990, 1991, Larry Wall
- |
- | Perl may be copied only under the terms of either the Artistic License or the
- | GNU General Public License, which may be found in the Perl 4.0 source kit.
- --
- All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
- 1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc
- --
- Pensu tutmonde; agu loke.
-