Skip to content

Commit 7680fea

Browse files
committed
perlvar: be more generous with spaces & semicolons
Example code doesn't need to be super terse.
1 parent b80054a commit 7680fea

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

pod/perlvar.pod

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ X<< $> >> X<$EUID> X<$EFFECTIVE_USER_ID>
357357

358358
The effective uid of this process. For example:
359359

360-
$< = $>; # set real to effective uid
361-
($<,$>) = ($>,$<); # swap real and effective uids
360+
$< = $>; # set real to effective uid
361+
($<, $>) = ($>, $<); # swap real and effective uids
362362

363363
You can change both the effective uid and the real uid at the same
364364
time by using C<POSIX::setuid()>. Changes to C<< $> >> require a check
@@ -379,19 +379,19 @@ X<$;> X<$SUBSEP> X<$SUBSCRIPT_SEPARATOR>
379379
The subscript separator for multidimensional array emulation. If you
380380
refer to a hash element as
381381

382-
$foo{$x,$y,$z}
382+
$foo{$x, $y, $z}
383383

384384
it really means
385385

386386
$foo{join($;, $x, $y, $z)}
387387

388388
But don't put
389389

390-
@foo{$x,$y,$z} # a slice--note the @
390+
@foo{$x, $y, $z} # a slice--note the @
391391

392392
which means
393393

394-
($foo{$x},$foo{$y},$foo{$z})
394+
($foo{$x}, $foo{$y}, $foo{$z})
395395

396396
Default is "\034", the same as SUBSEP in B<awk>. If your keys contain
397397
binary data there might not be any safe value for C<$;>.
@@ -423,7 +423,7 @@ As of v5.18.0, both keys and values stored in C<%ENV> are stringified.
423423

424424
my $foo = 1;
425425
$ENV{'bar'} = \$foo;
426-
if( ref $ENV{'bar'} ) {
426+
if ( ref $ENV{'bar'} ) {
427427
say "Pre 5.18.0 Behaviour";
428428
} else {
429429
say "Post 5.18.0 Behaviour";
@@ -621,7 +621,7 @@ C<$@> as usual.
621621

622622
Consider the code
623623

624-
perl -le'sub f { eval "BEGIN { f() }"; } f()'
624+
perl -le 'sub f { eval "BEGIN { f() }"; } f()'
625625

626626
each invocation of C<f()> will consume considerable C stack, and this
627627
variable is used to cause code like this to die instead of exhausting
@@ -639,9 +639,9 @@ completed, thus the innermost will execute before the ones which contain
639639
it have even finished compiling, and the depth will not go above 1. In
640640
fact the above code is equivalent to
641641

642-
BEGIN { $n+=4 }
643-
BEGIN { $n+=2 }
644-
BEGIN { $n+=1 }
642+
BEGIN { $n += 4; }
643+
BEGIN { $n += 2; }
644+
BEGIN { $n += 1; }
645645

646646
which makes it obvious why a ${^MAX_NESTED_EVAL_BEGIN_BLOCKS} of 1
647647
would not block this code.
@@ -675,7 +675,7 @@ X<%SIG>
675675
The hash C<%SIG> contains signal handlers for signals. For example:
676676

677677
sub handler { # 1st argument is signal name
678-
my($sig) = @_;
678+
my ($sig) = @_;
679679
print "Caught a SIG$sig--shutting down\n";
680680
close($LOG);
681681
exit(0);
@@ -929,7 +929,7 @@ following statements:
929929
my $this_perl = $^X;
930930
if ($^O ne 'VMS') {
931931
$this_perl .= $Config{_exe}
932-
unless $this_perl =~ m/$Config{_exe}$/i;
932+
unless $this_perl =~ m/$Config{_exe}$/i;
933933
}
934934

935935
Because many operating systems permit anyone with read access to
@@ -944,7 +944,7 @@ command or referenced as a file.
944944
my $secure_perl_path = $Config{perlpath};
945945
if ($^O ne 'VMS') {
946946
$secure_perl_path .= $Config{_exe}
947-
unless $secure_perl_path =~ m/$Config{_exe}$/i;
947+
unless $secure_perl_path =~ m/$Config{_exe}$/i;
948948
}
949949

950950
=back
@@ -956,7 +956,7 @@ effects. Perl sets these variables when it has completed a match
956956
successfully, so you should check the match result before using them.
957957
For instance:
958958

959-
if( /P(A)TT(ER)N/ ) {
959+
if ( /P(A)TT(ER)N/ ) {
960960
print "I found $1 and $2\n";
961961
}
962962

@@ -1038,14 +1038,14 @@ In Perl 5.6.0 the C<@-> and C<@+> dynamic arrays were introduced that
10381038
supply the indices of successful matches. So you could for example do
10391039
this:
10401040

1041-
$str =~ /pattern/;
1041+
$str =~ /pattern/ or die "No match";
10421042

10431043
print $`, $&, $'; # bad: performance hit
10441044

10451045
print # good: no performance hit
1046-
substr($str, 0, $-[0]),
1047-
substr($str, $-[0], $+[0]-$-[0]),
1048-
substr($str, $+[0]);
1046+
substr($str, 0, $-[0]),
1047+
substr($str, $-[0], $+[0] - $-[0]),
1048+
substr($str, $+[0]);
10491049

10501050
In Perl 5.10.0 the C</p> match operator flag and the C<${^PREMATCH}>,
10511051
C<${^MATCH}>, and C<${^POSTMATCH}> variables were introduced, that allowed
@@ -1098,7 +1098,7 @@ in nested blocks that have been exited already.
10981098
Note that the 0 index of C<@{^CAPTURE}> is equivalent to C<$1>, the 1 index
10991099
is equivalent to C<$2>, etc.
11001100

1101-
if ("foal"=~/(.)(.)(.)(.)/) {
1101+
if ("foal" =~ /(.)(.)(.)(.)/) {
11021102
print join "-", @{^CAPTURE};
11031103
}
11041104

@@ -1112,7 +1112,7 @@ letter equivalent to C<@{^CAPTURE}>. Also be aware that when
11121112
interpolating subscripts of this array you B<must> use the demarcated
11131113
variable form, for instance
11141114

1115-
print "${^CAPTURE[0]}"
1115+
print "${^CAPTURE[0]}";
11161116

11171117
see L<perldata/"Demarcated variable names using braces"> for more
11181118
information on this form and its uses.
@@ -1262,7 +1262,6 @@ The text matched by the used group most-recently closed (i.e. the group
12621262
with the rightmost closing parenthesis) of the last successful match.
12631263
(See L</Scoping Rules of Regex Variables>).
12641264

1265-
12661265
This is subtly different from C<$+>. For example in
12671266

12681267
"ab" =~ /^((.)(.))$/
@@ -1420,7 +1419,7 @@ Here's an example:
14201419
if ('1234' =~ /(?<A>1)(?<B>2)(?<A>3)(?<B>4)/) {
14211420
foreach my $bufname (sort keys %-) {
14221421
my $ary = $-{$bufname};
1423-
foreach my $idx (0..$#$ary) {
1422+
foreach my $idx (0 .. $#$ary) {
14241423
print "\$-{$bufname}[$idx] : ",
14251424
(defined($ary->[$idx])
14261425
? "'$ary->[$idx]'"
@@ -1590,7 +1589,7 @@ example:
15901589

15911590
Here is an example of how your own code can go broken:
15921591

1593-
for ( 1..3 ){
1592+
for ( 1 .. 3 ) {
15941593
$\ = "\r\n";
15951594
nasty_break();
15961595
print "$_";

0 commit comments

Comments
 (0)