Skip to content

Commit d91e686

Browse files
committed
perlvar: remove indirect object syntax
- remove the `method HANDLE EXPR` example - mention that an explicit `use IO::Handle` has not been required since perl v5.14 (that was 13 years ago) - remove the advice to prefer built-in variables over IO::Handle methods because: - `STDOUT->autoflush(1);` is about 200x more readable than `$|++;` or similar nonsense - loading IO::Handle isn't actually that expensive (and if it is, we should figure out how to speed up `$fh->autoflush` in core, not discourage programmers from using it) - the performance advice is from 1999 and hasn't been updated since (commits 1421858, 19799a2) - as far as I can tell, this advice is mostly Tom Christiansen's personal opinion and not the general consensus of the Perl community - move a comma from one paragraph to the next (technically unrelated, but it's in the general vicinity of the preceding changes)
1 parent e5d3a95 commit d91e686

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

pod/perlvar.pod

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,29 +1524,26 @@ This variable was added in Perl v5.10.0.
15241524

15251525
Variables that depend on the currently selected filehandle may be set
15261526
by calling an appropriate object method on the C<IO::Handle> object,
1527-
although this is less efficient than using the regular built-in
1527+
although this is slightly less efficient than using the regular built-in
15281528
variables. (Summary lines below for this contain the word HANDLE.)
1529-
First you must say
15301529

1531-
use IO::Handle;
1532-
1533-
after which you may use either
1530+
In Perl versions before v5.14.0, you had to say
15341531

1535-
method HANDLE EXPR
1532+
use IO::Handle;
15361533

1537-
or more safely,
1534+
before using
15381535

15391536
HANDLE->method(EXPR)
15401537

1538+
Since Perl v5.14.0, you can use all filehandles as objects without manually
1539+
loading any modules first.
1540+
15411541
Each method returns the old value of the C<IO::Handle> attribute. The
15421542
methods each take an optional EXPR, which, if supplied, specifies the
15431543
new value for the C<IO::Handle> attribute in question. If not
15441544
supplied, most methods do nothing to the current value--except for
15451545
C<autoflush()>, which will assume a 1 for you, just to be different.
15461546

1547-
Because loading in the C<IO::Handle> class is an expensive operation,
1548-
you should learn how to use the regular built-in variables.
1549-
15501547
A few of these variables are considered "read-only". This means that
15511548
if you try to assign to this variable, either directly or indirectly
15521549
through a reference, you'll raise a run-time exception.
@@ -1570,12 +1567,12 @@ But the following code is quite bad:
15701567
my $content = <$fh>;
15711568
close $fh;
15721569

1573-
since some other module, may want to read data from some file in the
1570+
since some other module may want to read data from some file in the
15741571
default "line mode", so if the code we have just presented has been
15751572
executed, the global value of C<$/> is now changed for any other code
15761573
running inside the same Perl interpreter.
15771574

1578-
Usually when a variable is localized you want to make sure that this
1575+
Usually when a variable is localized, you want to make sure that this
15791576
change affects the shortest scope possible. So unless you are already
15801577
inside some short C<{}> block, you should create one yourself. For
15811578
example:

0 commit comments

Comments
 (0)