Front page | perl.perl5.porters |
Postings from August 2009
[DOC] Modernization: where to put "my"?
Thread Next
From:
Flavio Poletti
Date:
August 30, 2009 00:10
Subject:
[DOC] Modernization: where to put "my"?
Message ID:
aeba50980908300009v4c83ca65q6c0f124562f50393@mail.gmail.com
DISCLAIMER: I hope not to annoy anyone here in p5p with stylistic
documentation issues like this, but perl5-documentation is virtually
deserted and it seems that all the doc job is done here nowadays. Maybe
if/once a documentation pumpking is appointed the discussion can be moved
there/elsewhere?
Hi all,
in the effort to modernize the docs, I think it would be good to add "my"
in front of most variable declarations and possibly assignments.
Anyway, sometimes the same variable name is used repeatedly in one example,
e.g. $scalar in the following example:
%hash = (foo => 11, bar => 22, baz => 33);
$scalar = delete $hash{foo}; # $scalar is 11
$scalar = delete @hash{qw(foo bar)}; # $scalar is 22
@array = delete @hash{qw(foo bar baz)}; # @array is (undef,undef,33)
Now, adding "my" to this can be tricky. On one hand it might be thought that
these could be regarded as alternatives, favouring a "my" in front of them
all:
my %hash = (foo => 11, bar => 22, baz => 33);
my $scalar = delete $hash{foo}; # $scalar is 11
my $scalar = delete @hash{qw(foo bar)}; # $scalar is 22
my @array = delete @hash{qw(foo bar baz)}; # @array is
(undef,undef,33)
On the other hand, copying and pasting this yields a warning message about
the second $scalar hiding the first one.
Now I wonder:
* is adding all these "my" really that useful? I think so for cut-and-paste
examples like this:
my ($package, $filename, $line) = caller;
* in case it is, just to convice the reader that "my" is the right choice
most of the times, which approach is better for the "proof-of-concept"
examples?
Cheers,
Flavio.
Thread Next
-
[DOC] Modernization: where to put "my"?
by Flavio Poletti