New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IO::Handle::getline() doco should note an important difference from <$io> #7993
Comments
From jm-perl.org@jmason.orgCreated by jm-perl.org@jmason.orgThis is a bug report for perl from jm-perl.org@jmason.org, ----------------------------------------------------------------- $io->getline However, there is one key difference: "while (<$io>)" and "while $io->getline Perl Info
|
From @schwernOn Tue, Jun 28, 2005 at 06:25:31PM -0000, Justin Mason wrote:
Confirmed. while(<FH>) must have some sort of special case to consider -- |
The RT System itself - Status changed from 'new' to 'open' |
From @demerphqOn 6/29/05, Michael G Schwern <schwern@pobox.com> wrote:
while (<FH>) { is documented to be equivelent to while (defined($_=<FH>)) { in perlvar I/O Operators. -- |
From @smpetersOn Wed, Jun 29, 2005 at 02:25:49PM +0200, demerphq wrote:
Then, how does the following sound to everyone... Inline Patch--- ext/IO/lib/IO/Handle.pm.old Sun Apr 4 08:32:35 2004
+++ ext/IO/lib/IO/Handle.pm Wed Jun 29 08:34:48 2005
@@ -117,7 +117,10 @@
This works like <$io> described in L<perlop/"I/O Operators">
except that it's more readable and can be safely called in a
-list context but still returns just one line.
+list context but still returns just one line. If used within a
+conditional statement, however, you will need to emulate the
+functionality of <$io> with C<defined($x = $io->getline)> where
+C<$x> is a scalar you have previously defined.
=item $io->getlines
Steve Peters
steve@fisharerojo.org |
From @tamiasOn Wed, Jun 29, 2005 at 08:37:29AM -0500, Steve Peters wrote:
Why not just use $_ there? Not only does that emulate the actual behavior Ronald |
From @smpetersOn Wed, Jun 29, 2005 at 10:24:29AM -0400, Ronald J Kimball wrote:
Well, I was hoping to confuse ;). Inline Patch--- ext/IO/lib/IO/Handle.pm.old Sun Apr 4 08:32:35 2004
+++ ext/IO/lib/IO/Handle.pm Wed Jun 29 10:43:47 2005
@@ -117,7 +117,9 @@
This works like <$io> described in L<perlop/"I/O Operators">
except that it's more readable and can be safely called in a
-list context but still returns just one line.
+list context but still returns just one line. If used within a
+conditional statement, however, you will need to emulate the
+functionality of <$io> with C<defined($_ = $io->getline)>.
Steve Peters
steve@fisharerojo.org |
From eric-amick@comcast.net
You mean C<< defined($_ = $io->getline) >> |
From @iabynOn Wed, Jun 29, 2005 at 10:47:45AM -0500, Steve Peters wrote:
not within any old conditional statement, only as the sole contents of a -- |
From @tamiasOn Wed, Jun 29, 2005 at 11:39:32PM +0100, Dave Mitchell wrote:
Or the conditional in a C-style for loop, I believe. Ronald |
From @iabynOn Wed, Jun 29, 2005 at 06:46:49PM -0400, Ronald J Kimball wrote:
Indeed. -- |
From @smpetersOn Wed, Jun 29, 2005 at 11:56:10PM +0100, Dave Mitchell wrote:
So, indeed, I hope that the third time is the charm... Inline Patch--- ext/IO/lib/IO/Handle.pm.old Sun Apr 4 08:32:35 2004
+++ ext/IO/lib/IO/Handle.pm Wed Jun 29 21:46:44 2005
@@ -117,7 +117,9 @@
This works like <$io> described in L<perlop/"I/O Operators">
except that it's more readable and can be safely called in a
-list context but still returns just one line.
+list context but still returns just one line. If used as the conditional
+within a C<while> or C-style C<for> loop, however, you will need to
+emulate the functionality of <$io> with C<defined($_ = $io->getline)>.
=item $io->getlines
Steve Peters
steve@fisharerojo.org |
From @rgsSteve Peters wrote:
Thanks, applied (after having fixed the pod markup.) |
@iabyn - Status changed from 'open' to 'resolved' |
From nick@ing-simmons.netJustin Mason <perl5-porters@perl.org> writes:
Debatable - <$io> is idomatic perl
And of course $io->getline is slower The whole IO::* thing was IMHO the biggest mistake Graham Barr & I made But we were in that new-to-objects phase where everything had to be
Not that while (defined <$io>)
|
From nick@ing-simmons.netMichael G Schwern <schwern@pobox.com> writes:
Yes. The kind of special case that is easy to do with operators. |
From nick@ing-simmons.netSteve Peters <steve@fisharerojo.org> writes:
By which time you have lost ALL the alleged benefits and are still paying The only reason for using ->getline is if you have some reason
|
From jm@jmason.org-----BEGIN PGP SIGNED MESSAGE----- Nick Ing-Simmons via RT writes:
sometimes this is indeed the case -- e.g. in our case, it's in - --j. iD8DBQFCyteHMJF5cimLx9ARAoSCAJ4z8Egylfx7Dmpe9H0iF/Xn6iP1pwCgheOz |
From nick@ing-simmons.netJustin Mason <jm@jmason.org> writes:
Just to be clear: As far as I am aware all _sockets_ are real filehandles And if (reference to) IO (or GV) is "blessed" to make it an object What I mean't was something more abstract like: {package Fake; sub new { sub getline } package main; sub useit # IO::Handle # Something else entirely |
Migrated from rt.perl.org#36417 (status was 'resolved')
Searchable as RT36417$
The text was updated successfully, but these errors were encountered: