Skip to content
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

Remove IO::File example from perlfunc #12862

Closed
p5pRT opened this issue Mar 19, 2013 · 19 comments
Closed

Remove IO::File example from perlfunc #12862

p5pRT opened this issue Mar 19, 2013 · 19 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 19, 2013

Migrated from rt.perl.org#117223 (status was 'resolved')

Searchable as RT117223$

@p5pRT
Copy link
Author

p5pRT commented Mar 19, 2013

From @epa

Created by @epa

Perfunc contains some example code for 'read_myfile_munged'.
There are various problems with that code but I don't need to
list them all here - the simplest thing is just to remove it
since IO​::File is no longer needed to create filehandles that
get automatically closed.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.16.2:

Configured by Red Hat, Inc. at Mon Feb 18 16:52:57 UTC 2013.

Summary of my perl5 (revision 5 version 16 subversion 2) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-279.19.1.el6.x86_64, archname=x86_64-linux-thread-multi
    uname='linux buildvm-11.phx2.fedoraproject.org 2.6.32-279.19.1.el6.x86_64 #1 smp sat nov 24 14:35:28 est 2012 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4  -m64 -mtune=generic -Dccdlflags=-Wl,--enable-new-dtags -Dlddlflags=-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4  -m64 -mtune=generic -Wl,-z,relro  -DDEBUGGING=-g -Dversion=5.16.2 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin -Dusesitecustomize'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.7.2 20121109 (Red Hat 4.7.2-8)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector'
    libpth=/usr/local/lib64 /lib64 /usr/lib64
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.16'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wl,-z,relro '

Locally applied patches:
    


@INC for perl 5.16.2:
    /home/eda/lib/perl5/
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib64/perl5
    /usr/share/perl5
    .


Environment for perl 5.16.2:
    HOME=/home/tradingsystems
    LANG=en_GB.UTF-8
    LANGUAGE (unset)
    LC_COLLATE=C
    LC_CTYPE=en_GB.UTF-8
    LC_MESSAGES=en_GB.UTF-8
    LC_MONETARY=en_GB.UTF-8
    LC_NUMERIC=en_GB.UTF-8
    LC_TIME=en_GB.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/eda/bin:/home/eda/bin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/sbin:/usr/sbin
    PERL5LIB=/home/eda/lib/perl5/
    PERL_BADLANG (unset)
    SHELL=/bin/bash


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Mar 22, 2013

From @jkeenan

On Tue Mar 19 10​:42​:44 2013, eda@​waniasset.com wrote​:

This is a bug report for perl from eda@​waniasset.com,
generated with the help of perlbug 1.39 running under perl 5.16.2.

-----------------------------------------------------------------
[Please describe your issue here]

Perfunc contains some example code for 'read_myfile_munged'.
There are various problems with that code but I don't need to
list them all here - the simplest thing is just to remove it
since IO​::File is no longer needed to create filehandles that
get automatically closed.

Would you be able to provide a patch?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Mar 22, 2013

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Mar 22, 2013

From @epa

Inline Patch
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 7088a9e..a249af2 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -3865,12 +3865,6 @@ FILEHANDLE is an expression, its value is the real filehandle.  (This is
 considered a symbolic reference, so C<use strict "refs"> should I<not> be
 in effect.)

-If EXPR is omitted, the global (package) scalar variable of the same
-name as the FILEHANDLE contains the filename.  (Note that lexical
-variables--those declared with C<my> or C<state>--will not work for this
-purpose; so if you're using C<my> or C<state>, specify EXPR in your
-call to open.)
-
 If three (or more) arguments are specified, the open mode (including
 optional encoding) in the second argument are distinct from the filename in
 the third.  If MODE is C<< < >> or nothing, the file is opened for input.
@@ -3953,6 +3947,31 @@ where you want to format a suitable error message (but there are
 modules that can help with that problem)) always check
 the return value from opening a file.

+The filehandle will be closed when its reference count reaches
+zero.  If it is a lexically scoped variable declared with C<my>,
+that usually means the end of the enclosing scope.  However,
+this automatic close does not check for errors, so it is better
+to explicitly close filehandles, especially those used for writing:
+
+    close($handle)
+       || warn "close failed: $!";
+
+An older style is to use a bareword as the filehandle, as
+
+    open(FH, "<", "input.txt")
+       or die "cannot open < input.txt: $!";
+
+Then you can use FH as the filenandle, in C<< close FH >> and C<< <FH> >> and so on.
+Note that it's a global variable, so this form is not recommeded in new code.
+As a shortcut a one-argument call takes the filename from the global scalar variable
+of the same name as the filehandle:
+
+    $ARTICLE = 100;
+    open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
+
+Here $ARTICLE must be a global (package) scalar variable - not one
+declared with C<my> or C<state>.
+
 As a special case the three-argument form with a read/write mode and the third
 argument being C<undef>:

@@ -3977,10 +3996,6 @@ To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:

 General examples:

-    $ARTICLE = 100;
-    open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
-    while (<ARTICLE>) {...
-
     open(LOG, ">>/usr/spool/news/twitlog");  # (log is reserved)
     # if the open fails, output is discarded

@@ -4225,34 +4240,6 @@ interpretation.  For example:
     seek(HANDLE, 0, 0);
     print "File contains: ", <HANDLE>;

-Using the constructor from the C<IO::Handle> package (or one of its
-subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
-filehandles that have the scope of the variables used to hold them, then
-automatically (but silently) close once their reference counts become
-zero, typically at scope exit:
-
-    use IO::File;
-    #...
-    sub read_myfile_munged {
-        my $ALL = shift;
-       # or just leave it undef to autoviv
-        my $handle = IO::File->new;
-        open($handle, "<", "myfile") or die "myfile: $!";
-        $first = <$handle>
-            or return ();     # Automatically closed here.
-        mung($first) or die "mung failed";  # Or here.
-        return (first, <$handle>) if $ALL;  # Or here.
-        return $first;                      # Or here.
-    }
-
-B<WARNING:> The previous example has a bug because the automatic
-close that happens when the refcount on C<handle> reaches zero does not
-properly detect and report failures.  I<Always> close the handle
-yourself and inspect the return value.
-
-    close($handle)
-       || warn "close failed: $!";
-
 See L</seek> for some details about mixing reading and writing.

 Portability issues: L<perlport/open>.

______________________________________________________________________ This email has been scanned by the Symantec Email Security\.cloud service\. For more information please visit http​://www\.symanteccloud\.com \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

@p5pRT
Copy link
Author

p5pRT commented Mar 22, 2013

From @b2gills

Looks good to me.

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2013

From @tamias

On Fri, Mar 22, 2013 at 10​:45​:28AM +0000, Ed Avis wrote​:

diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 7088a9e..a249af2 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@​@​ -3865,12 +3865,6 @​@​ FILEHANDLE is an expression, its value is the real filehandle. (This is

+Then you can use FH as the filenandle, in C<< close FH >> and C<< <FH> >> and so on.
+Note that it's a global variable, so this form is not recommeded in new code.

"recommended"

+As a shortcut a one-argument call takes the filename from the global scalar variable
+of the same name as the filehandle​:

How about wrapping that paragraph so the lines are under 80 characters, as
in the rest of the patch?

Ronald

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2013

From @epa

Please do change the spelling of recommended and do any needed word-wrapping
if you decide to apply the patch.

--
Ed Avis <eda@​waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http​://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2013

From @tonycoz

On Wed Mar 27 03​:22​:13 2013, eda@​waniasset.com wrote​:

Please do change the spelling of recommended and do any needed
word-wrapping
if you decide to apply the patch.

I've attached an updated version of the patch that applies to blead,
I'll apply it in a few days if no-one objects to it.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2013

From @tonycoz

0001-perl-117223-Remove-IO-File-example-from-perlfunc.patch
From 78d8752222b627b5c033e2861a981c17fbd43d1b Mon Sep 17 00:00:00 2001
From: Ed Avis <eda@waniasset.com>
Date: Fri, 5 Jul 2013 15:03:41 +1000
Subject: [PATCH] [perl #117223] Remove IO::File example from perlfunc

updated to apply to blead, minor spelling and word wrap fixes by Tony
Cook.
---
 AUTHORS          |    1 +
 pod/perlfunc.pod |   65 +++++++++++++++++++++++-------------------------------
 2 files changed, 28 insertions(+), 38 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 01b6e1d..20bddda 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -345,6 +345,7 @@ Drew Stephens			<drewgstephens@gmail.com>
 Duke Leto			<jonathan@leto.net>
 Duncan Findlay			<duncf@debian.org>
 E. Choroba			<choroba@weed.(none)>
+Ed Avis				<eda@waniasset.com>
 Ed Mooring			<mooring@Lynx.COM>
 Ed Santiago			<esm@pobox.com>
 Eddy Tan			<eddy.net@gmail.com>
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 167eaef..82ac7d9 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -3907,12 +3907,6 @@ FILEHANDLE is an expression, its value is the real filehandle.  (This is
 considered a symbolic reference, so C<use strict "refs"> should I<not> be
 in effect.)
 
-If EXPR is omitted, the global (package) scalar variable of the same
-name as the FILEHANDLE contains the filename.  (Note that lexical 
-variables--those declared with C<my> or C<state>--will not work for this
-purpose; so if you're using C<my> or C<state>, specify EXPR in your
-call to open.)
-
 If three (or more) arguments are specified, the open mode (including
 optional encoding) in the second argument are distinct from the filename in
 the third.  If MODE is C<< < >> or nothing, the file is opened for input.
@@ -3995,6 +3989,33 @@ where you want to format a suitable error message (but there are
 modules that can help with that problem)) always check
 the return value from opening a file.  
 
+The filehandle will be closed when its reference count reaches zero.
+If it is a lexically scoped variable declared with C<my>, that usually
+means the end of the enclosing scope.  However, this automatic close
+does not check for errors, so it is better to explicitly close
+filehandles, especially those used for writing:
+
+    close($handle)
+       || warn "close failed: $!";
+
+An older style is to use a bareword as the filehandle, as
+
+    open(FH, "<", "input.txt")
+       or die "cannot open < input.txt: $!";
+
+Then you can use C<FH> as the filenandle, in C<< close FH >> and C<<
+<FH> >> and so on.  Note that it's a global variable, so this form is
+not recommended in new code.
+
+As a shortcut a one-argument call takes the filename from the global
+scalar variable of the same name as the filehandle:
+
+    $ARTICLE = 100;
+    open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
+
+Here C<$ARTICLE> must be a global (package) scalar variable - not one
+declared with C<my> or C<state>.
+
 As a special case the three-argument form with a read/write mode and the third
 argument being C<undef>:
 
@@ -4019,10 +4040,6 @@ To (re)open C<STDOUT> or C<STDERR> as an in-memory file, close it first:
 
 General examples:
 
-    $ARTICLE = 100;
-    open(ARTICLE) or die "Can't find article $ARTICLE: $!\n";
-    while (<ARTICLE>) {...
-
     open(LOG, ">>/usr/spool/news/twitlog");  # (log is reserved)
     # if the open fails, output is discarded
 
@@ -4267,34 +4284,6 @@ interpretation.  For example:
     seek(HANDLE, 0, 0);
     print "File contains: ", <HANDLE>;
 
-Using the constructor from the C<IO::Handle> package (or one of its
-subclasses, such as C<IO::File> or C<IO::Socket>), you can generate anonymous
-filehandles that have the scope of the variables used to hold them, then
-automatically (but silently) close once their reference counts become
-zero, typically at scope exit:
-
-    use IO::File;
-    #...
-    sub read_myfile_munged {
-        my $ALL = shift;
-	# or just leave it undef to autoviv
-        my $handle = IO::File->new;
-        open($handle, "<", "myfile") or die "myfile: $!";
-        $first = <$handle>
-            or return ();     # Automatically closed here.
-        mung($first) or die "mung failed";  # Or here.
-        return (first, <$handle>) if $ALL;  # Or here.
-        return $first;                      # Or here.
-    }
-
-B<WARNING:> The previous example has a bug because the automatic
-close that happens when the refcount on C<handle> reaches zero does not
-properly detect and report failures.  I<Always> close the handle
-yourself and inspect the return value.
-
-    close($handle) 
-	|| warn "close failed: $!";
-
 See L</seek> for some details about mixing reading and writing.
 
 Portability issues: L<perlport/open>.
-- 
1.7.10.4

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2013

From @cpansprout

On Thu Jul 04 22​:12​:03 2013, tonyc wrote​:

On Wed Mar 27 03​:22​:13 2013, eda@​waniasset.com wrote​:

Please do change the spelling of recommended and do any needed
word-wrapping
if you decide to apply the patch.

I've attached an updated version of the patch that applies to blead,
I'll apply it in a few days if no-one objects to it.

It looks good to me.

(I tend to disagree with Ed Avis on many issues, so I am surprised how
much I like this patch. :-)

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Jul 5, 2013

From @jkeenan

On 7/5/13 1​:12 AM, Tony Cook via RT wrote​:

On Wed Mar 27 03​:22​:13 2013, eda@​waniasset.com wrote​:

Please do change the spelling of recommended and do any needed
word-wrapping
if you decide to apply the patch.

I've attached an updated version of the patch that applies to blead,
I'll apply it in a few days if no-one objects to it.

One spelling correction​:
s/filenandle/filehandle/

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

From @tonycoz

On Fri Jul 05 15​:57​:00 2013, jkeen@​verizon.net wrote​:

On 7/5/13 1​:12 AM, Tony Cook via RT wrote​:

On Wed Mar 27 03​:22​:13 2013, eda@​waniasset.com wrote​:

Please do change the spelling of recommended and do any needed
word-wrapping
if you decide to apply the patch.

I've attached an updated version of the patch that applies to blead,
I'll apply it in a few days if no-one objects to it.

One spelling correction​:
s/filenandle/filehandle/

Applied as 1578dcc with this fix.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jul 16, 2013

@tonycoz - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Oct 13, 2014

From @khwilliamson

I'm reopening this so that the issues raised in
http​://blog.nu42.com/2014/10/why-was-documentation-for-single.html

can be resolved

--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Oct 13, 2014

@khwilliamson - Status changed from 'resolved' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Oct 13, 2014

From @epa

Thanks for looking at this. However, I think the behaviour of a single-argument open() call is still documented, just with different wording.
See "As a shortcut..." in the earlier diff.

--
Ed Avis <eda@​waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http​://www.symanteccloud.com
______________________________________________________________________

@p5pRT
Copy link
Author

p5pRT commented Oct 19, 2014

From @jkeenan

On Mon Oct 13 10​:10​:53 2014, khw wrote​:

I'm reopening this so that the issues raised in
http​://blog.nu42.com/2014/10/why-was-documentation-for-single.html

can be resolved

I've read that blog post a couple of times. It has been revised in light of the comments posted to it. Ed Avis pointed to the section of 'perldoc -f open' that addressed the concerns raised in the blog post. So I think this RT can be closed again.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2016

From @dcollinsn

On Sun Oct 19 16​:14​:17 2014, jkeenan wrote​:

On Mon Oct 13 10​:10​:53 2014, khw wrote​:

I'm reopening this so that the issues raised in
http​://blog.nu42.com/2014/10/why-was-documentation-for-single.html

can be resolved

I've read that blog post a couple of times. It has been revised in
light of the comments posted to it. Ed Avis pointed to the section of
'perldoc -f open' that addressed the concerns raised in the blog post.
So I think this RT can be closed again.

Agreed, and one-arg open() is documented in blead ("As a shortcut a one-argument call takes the filename from the global scalar variable of the same name as the filehandle​:")

Un-warnocking and closing resolved.

--
Respectfully,
Dan Collins

@p5pRT p5pRT closed this as completed Oct 6, 2016
@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2016

@dcollinsn - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant