Skip to content

Commit 6a40a72

Browse files
shlomifjkeenan
authored andcommitted
Convert tabs in indentation to spaces.
This is so it will display correctly with every tab-step/tab-size.
1 parent 0e9f069 commit 6a40a72

File tree

1 file changed

+65
-65
lines changed

1 file changed

+65
-65
lines changed

pod/perldsc.pod

+65-65
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Perl lets us have complex data structures. You can write something like
99
this and all of a sudden, you'd have an array with three dimensions!
1010

1111
for $x (1 .. 10) {
12-
for $y (1 .. 10) {
13-
for $z (1 .. 10) {
14-
$AoA[$x][$y][$z] =
15-
$x ** $y + $z;
16-
}
17-
}
12+
for $y (1 .. 10) {
13+
for $z (1 .. 10) {
14+
$AoA[$x][$y][$z] =
15+
$x ** $y + $z;
16+
}
17+
}
1818
}
1919

2020
Alas, however simple this may appear, underneath it's a much more
@@ -85,10 +85,10 @@ level. It's just that you can I<use> it as though it were a
8585
two-dimensional one. This is actually the way almost all C
8686
multidimensional arrays work as well.
8787

88-
$array[7][12] # array of arrays
89-
$array[7]{string} # array of hashes
90-
$hash{string}[7] # hash of arrays
91-
$hash{string}{'another string'} # hash of hashes
88+
$array[7][12] # array of arrays
89+
$array[7]{string} # array of hashes
90+
$hash{string}[7] # hash of arrays
91+
$hash{string}{'another string'} # hash of hashes
9292

9393
Now, because the top level contains only references, if you try to print
9494
out your array in with a simple print() function, you'll get something
@@ -116,25 +116,25 @@ repeatedly. Here's the case where you just get the count instead
116116
of a nested array:
117117

118118
for $i (1..10) {
119-
@array = somefunc($i);
120-
$AoA[$i] = @array; # WRONG!
119+
@array = somefunc($i);
120+
$AoA[$i] = @array; # WRONG!
121121
}
122122

123123
That's just the simple case of assigning an array to a scalar and getting
124124
its element count. If that's what you really and truly want, then you
125125
might do well to consider being a tad more explicit about it, like this:
126126

127127
for $i (1..10) {
128-
@array = somefunc($i);
129-
$counts[$i] = scalar @array;
128+
@array = somefunc($i);
129+
$counts[$i] = scalar @array;
130130
}
131131

132132
Here's the case of taking a reference to the same memory location
133133
again and again:
134134

135135
for $i (1..10) {
136-
@array = somefunc($i);
137-
$AoA[$i] = \@array; # WRONG!
136+
@array = somefunc($i);
137+
$AoA[$i] = \@array; # WRONG!
138138
}
139139

140140
So, what's the big problem with that? It looks right, doesn't it?
@@ -148,12 +148,12 @@ the following C program:
148148

149149
#include <pwd.h>
150150
main() {
151-
struct passwd *getpwnam(), *rp, *dp;
152-
rp = getpwnam("root");
153-
dp = getpwnam("daemon");
151+
struct passwd *getpwnam(), *rp, *dp;
152+
rp = getpwnam("root");
153+
dp = getpwnam("daemon");
154154

155-
printf("daemon name is %s\nroot name is %s\n",
156-
dp->pw_name, rp->pw_name);
155+
printf("daemon name is %s\nroot name is %s\n",
156+
dp->pw_name, rp->pw_name);
157157
}
158158

159159
Which will print
@@ -169,8 +169,8 @@ broken code fragments:
169169
X<[]> X<{}>
170170

171171
for $i (1..10) {
172-
@array = somefunc($i);
173-
$AoA[$i] = [ @array ];
172+
@array = somefunc($i);
173+
$AoA[$i] = [ @array ];
174174
}
175175

176176
The square brackets make a reference to a new array with a I<copy>
@@ -181,8 +181,8 @@ Note that this will produce something similar, but it's
181181
much harder to read:
182182

183183
for $i (1..10) {
184-
@array = 0 .. $i;
185-
@{$AoA[$i]} = @array;
184+
@array = 0 .. $i;
185+
@{$AoA[$i]} = @array;
186186
}
187187

188188
Is it the same? Well, maybe so--and maybe not. The subtle difference
@@ -235,9 +235,9 @@ do the right thing behind the scenes.
235235

236236
In summary:
237237

238-
$AoA[$i] = [ @array ]; # usually best
239-
$AoA[$i] = \@array; # perilous; just how my() was that array?
240-
@{ $AoA[$i] } = @array; # way too tricky for most programmers
238+
$AoA[$i] = [ @array ]; # usually best
239+
$AoA[$i] = \@array; # perilous; just how my() was that array?
240+
@{ $AoA[$i] } = @array; # way too tricky for most programmers
241241

242242

243243
=head1 CAVEAT ON PRECEDENCE
@@ -247,8 +247,8 @@ Speaking of things like C<@{$AoA[$i]}>, the following are actually the
247247
same thing:
248248
X<< -> >>
249249

250-
$aref->[2][2] # clear
251-
$$aref[2][2] # confusing
250+
$aref->[2][2] # clear
251+
$$aref[2][2] # confusing
252252

253253
That's because Perl's precedence rules on its five prefix dereferencers
254254
(which look like someone swearing: C<$ @ * % &>) make them bind more
@@ -279,9 +279,9 @@ also disallow accidental "symbolic dereferencing". Therefore if you'd done
279279
this:
280280

281281
my $aref = [
282-
[ "fred", "barney", "pebbles", "bambam", "dino", ],
283-
[ "homer", "bart", "marge", "maggie", ],
284-
[ "george", "jane", "elroy", "judy", ],
282+
[ "fred", "barney", "pebbles", "bambam", "dino", ],
283+
[ "homer", "bart", "marge", "maggie", ],
284+
[ "george", "jane", "elroy", "judy", ],
285285
];
286286

287287
print $aref[2][2];
@@ -304,21 +304,21 @@ For example, given the assignment to $AoA above, here's the debugger output:
304304
DB<1> x $AoA
305305
$AoA = ARRAY(0x13b5a0)
306306
0 ARRAY(0x1f0a24)
307-
0 'fred'
308-
1 'barney'
309-
2 'pebbles'
310-
3 'bambam'
311-
4 'dino'
307+
0 'fred'
308+
1 'barney'
309+
2 'pebbles'
310+
3 'bambam'
311+
4 'dino'
312312
1 ARRAY(0x13b558)
313-
0 'homer'
314-
1 'bart'
315-
2 'marge'
316-
3 'maggie'
313+
0 'homer'
314+
1 'bart'
315+
2 'marge'
316+
3 'maggie'
317317
2 ARRAY(0x13b540)
318-
0 'george'
319-
1 'jane'
320-
2 'elroy'
321-
3 'judy'
318+
0 'george'
319+
1 'jane'
320+
2 'elroy'
321+
3 'judy'
322322

323323
=head1 CODE EXAMPLES
324324

@@ -454,10 +454,10 @@ X<hash of arrays> X<HoA>
454454

455455
# print the whole thing sorted by number of members and name
456456
foreach $family ( sort {
457-
@{$HoA{$b}} <=> @{$HoA{$a}}
458-
||
459-
$a cmp $b
460-
} keys %HoA )
457+
@{$HoA{$b}} <=> @{$HoA{$a}}
458+
||
459+
$a cmp $b
460+
} keys %HoA )
461461
{
462462
print "$family: ", join(", ", sort @{ $HoA{$family} }), "\n";
463463
}
@@ -560,19 +560,19 @@ X<hash of hashes> X<HoH>
560560

561561
%HoH = (
562562
flintstones => {
563-
lead => "fred",
564-
pal => "barney",
563+
lead => "fred",
564+
pal => "barney",
565565
},
566566
jetsons => {
567-
lead => "george",
568-
wife => "jane",
569-
"his boy" => "elroy",
567+
lead => "george",
568+
wife => "jane",
569+
"his boy" => "elroy",
570570
},
571571
simpsons => {
572-
lead => "homer",
573-
wife => "marge",
574-
kid => "bart",
575-
},
572+
lead => "homer",
573+
wife => "marge",
574+
kid => "bart",
575+
},
576576
);
577577

578578
=head2 Generation of a HASH OF HASHES
@@ -681,12 +681,12 @@ Here's a sample showing how to create and use a record whose fields are of
681681
many different sorts:
682682

683683
$rec = {
684-
TEXT => $string,
685-
SEQUENCE => [ @old_values ],
686-
LOOKUP => { %some_table },
687-
THATCODE => \&some_function,
688-
THISCODE => sub { $_[0] ** $_[1] },
689-
HANDLE => \*STDOUT,
684+
TEXT => $string,
685+
SEQUENCE => [ @old_values ],
686+
LOOKUP => { %some_table },
687+
THATCODE => \&some_function,
688+
THISCODE => sub { $_[0] ** $_[1] },
689+
HANDLE => \*STDOUT,
690690
};
691691

692692
print $rec->{TEXT};

0 commit comments

Comments
 (0)