Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit facde2a

Browse files
committed
Clean up Perl code according to perlcritic
Fix all perlcritic warnings of severity level 5, except in src/backend/utils/Gen_dummy_probes.pl, which is automatically generated. Reviewed-by: Dagfinn Ilmari Mannsåker <[email protected]> Reviewed-by: Daniel Gustafsson <[email protected]>
1 parent de4da16 commit facde2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+360
-358
lines changed

contrib/intarray/bench/create_test.pl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
1616
EOT
1717

18-
open(MSG, ">message.tmp") || die;
19-
open(MAP, ">message_section_map.tmp") || die;
18+
open(my $msg, '>', "message.tmp") || die;
19+
open(my $map, '>', "message_section_map.tmp") || die;
2020

2121
srand(1);
2222

@@ -42,16 +42,16 @@
4242
}
4343
if ($#sect < 0 || rand() < 0.1)
4444
{
45-
print MSG "$i\t\\N\n";
45+
print $msg "$i\t\\N\n";
4646
}
4747
else
4848
{
49-
print MSG "$i\t{" . join(',', @sect) . "}\n";
50-
map { print MAP "$i\t$_\n" } @sect;
49+
print $msg "$i\t{" . join(',', @sect) . "}\n";
50+
map { print $map "$i\t$_\n" } @sect;
5151
}
5252
}
53-
close MAP;
54-
close MSG;
53+
close $map;
54+
close $msg;
5555

5656
copytable('message');
5757
copytable('message_section_map');
@@ -79,8 +79,8 @@ sub copytable
7979
my $t = shift;
8080

8181
print "COPY $t from stdin;\n";
82-
open(FFF, "$t.tmp") || die;
83-
while (<FFF>) { print; }
84-
close FFF;
82+
open(my $fff, '<', "$t.tmp") || die;
83+
while (<$fff>) { print; }
84+
close $fff;
8585
print "\\.\n";
8686
}

doc/src/sgml/generate-errcodes-table.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
print
1010
"<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
1111

12-
open my $errcodes, $ARGV[0] or die;
12+
open my $errcodes, '<', $ARGV[0] or die;
1313

1414
while (<$errcodes>)
1515
{

doc/src/sgml/mk_feature_tables.pl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
my $yesno = $ARGV[0];
88

9-
open PACK, $ARGV[1] or die;
9+
open my $pack, '<', $ARGV[1] or die;
1010

1111
my %feature_packages;
1212

13-
while (<PACK>)
13+
while (<$pack>)
1414
{
1515
chomp;
1616
my ($fid, $pname) = split /\t/;
@@ -24,13 +24,13 @@
2424
}
2525
}
2626

27-
close PACK;
27+
close $pack;
2828

29-
open FEAT, $ARGV[2] or die;
29+
open my $feat, '<', $ARGV[2] or die;
3030

3131
print "<tbody>\n";
3232

33-
while (<FEAT>)
33+
while (<$feat>)
3434
{
3535
chomp;
3636
my ($feature_id, $feature_name, $subfeature_id,
@@ -69,4 +69,4 @@
6969

7070
print "</tbody>\n";
7171

72-
close FEAT;
72+
close $feat;

src/backend/catalog/Catalog.pm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ sub Catalogs
4444
$catalog{columns} = [];
4545
$catalog{data} = [];
4646

47-
open(INPUT_FILE, '<', $input_file) || die "$input_file: $!";
47+
open(my $ifh, '<', $input_file) || die "$input_file: $!";
4848

4949
my ($filename) = ($input_file =~ m/(\w+)\.h$/);
5050
my $natts_pat = "Natts_$filename";
5151

5252
# Scan the input file.
53-
while (<INPUT_FILE>)
53+
while (<$ifh>)
5454
{
5555

5656
# Strip C-style comments.
@@ -59,7 +59,7 @@ sub Catalogs
5959
{
6060

6161
# handle multi-line comments properly.
62-
my $next_line = <INPUT_FILE>;
62+
my $next_line = <$ifh>;
6363
die "$input_file: ends within C-style comment\n"
6464
if !defined $next_line;
6565
$_ .= $next_line;
@@ -211,7 +211,7 @@ sub Catalogs
211211
}
212212
}
213213
$catalogs{$catname} = \%catalog;
214-
close INPUT_FILE;
214+
close $ifh;
215215
}
216216
return \%catalogs;
217217
}

src/backend/catalog/genbki.pl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@
6666
# Open temp files
6767
my $tmpext = ".tmp$$";
6868
my $bkifile = $output_path . 'postgres.bki';
69-
open BKI, '>', $bkifile . $tmpext
69+
open my $bki, '>', $bkifile . $tmpext
7070
or die "can't open $bkifile$tmpext: $!";
7171
my $schemafile = $output_path . 'schemapg.h';
72-
open SCHEMAPG, '>', $schemafile . $tmpext
72+
open my $schemapg, '>', $schemafile . $tmpext
7373
or die "can't open $schemafile$tmpext: $!";
7474
my $descrfile = $output_path . 'postgres.description';
75-
open DESCR, '>', $descrfile . $tmpext
75+
open my $descr, '>', $descrfile . $tmpext
7676
or die "can't open $descrfile$tmpext: $!";
7777
my $shdescrfile = $output_path . 'postgres.shdescription';
78-
open SHDESCR, '>', $shdescrfile . $tmpext
78+
open my $shdescr, '>', $shdescrfile . $tmpext
7979
or die "can't open $shdescrfile$tmpext: $!";
8080

8181
# Fetch some special data that we will substitute into the output file.
@@ -97,7 +97,7 @@
9797
# Generate postgres.bki, postgres.description, and postgres.shdescription
9898

9999
# version marker for .bki file
100-
print BKI "# PostgreSQL $major_version\n";
100+
print $bki "# PostgreSQL $major_version\n";
101101

102102
# vars to hold data needed for schemapg.h
103103
my %schemapg_entries;
@@ -110,7 +110,7 @@
110110

111111
# .bki CREATE command for this catalog
112112
my $catalog = $catalogs->{$catname};
113-
print BKI "create $catname $catalog->{relation_oid}"
113+
print $bki "create $catname $catalog->{relation_oid}"
114114
. $catalog->{shared_relation}
115115
. $catalog->{bootstrap}
116116
. $catalog->{without_oids}
@@ -120,7 +120,7 @@
120120
my @attnames;
121121
my $first = 1;
122122

123-
print BKI " (\n";
123+
print $bki " (\n";
124124
foreach my $column (@{ $catalog->{columns} })
125125
{
126126
my $attname = $column->{name};
@@ -130,27 +130,27 @@
130130

131131
if (!$first)
132132
{
133-
print BKI " ,\n";
133+
print $bki " ,\n";
134134
}
135135
$first = 0;
136136

137-
print BKI " $attname = $atttype";
137+
print $bki " $attname = $atttype";
138138

139139
if (defined $column->{forcenotnull})
140140
{
141-
print BKI " FORCE NOT NULL";
141+
print $bki " FORCE NOT NULL";
142142
}
143143
elsif (defined $column->{forcenull})
144144
{
145-
print BKI " FORCE NULL";
145+
print $bki " FORCE NULL";
146146
}
147147
}
148-
print BKI "\n )\n";
148+
print $bki "\n )\n";
149149

150150
# open it, unless bootstrap case (create bootstrap does this automatically)
151151
if ($catalog->{bootstrap} eq '')
152152
{
153-
print BKI "open $catname\n";
153+
print $bki "open $catname\n";
154154
}
155155

156156
if (defined $catalog->{data})
@@ -175,17 +175,17 @@
175175

176176
# Write to postgres.bki
177177
my $oid = $row->{oid} ? "OID = $row->{oid} " : '';
178-
printf BKI "insert %s( %s)\n", $oid, $row->{bki_values};
178+
printf $bki "insert %s( %s)\n", $oid, $row->{bki_values};
179179

180180
# Write comments to postgres.description and postgres.shdescription
181181
if (defined $row->{descr})
182182
{
183-
printf DESCR "%s\t%s\t0\t%s\n", $row->{oid}, $catname,
183+
printf $descr "%s\t%s\t0\t%s\n", $row->{oid}, $catname,
184184
$row->{descr};
185185
}
186186
if (defined $row->{shdescr})
187187
{
188-
printf SHDESCR "%s\t%s\t%s\n", $row->{oid}, $catname,
188+
printf $shdescr "%s\t%s\t%s\n", $row->{oid}, $catname,
189189
$row->{shdescr};
190190
}
191191
}
@@ -267,7 +267,7 @@
267267
}
268268
}
269269

270-
print BKI "close $catname\n";
270+
print $bki "close $catname\n";
271271
}
272272

273273
# Any information needed for the BKI that is not contained in a pg_*.h header
@@ -276,19 +276,19 @@
276276
# Write out declare toast/index statements
277277
foreach my $declaration (@{ $catalogs->{toasting}->{data} })
278278
{
279-
print BKI $declaration;
279+
print $bki $declaration;
280280
}
281281

282282
foreach my $declaration (@{ $catalogs->{indexing}->{data} })
283283
{
284-
print BKI $declaration;
284+
print $bki $declaration;
285285
}
286286

287287

288288
# Now generate schemapg.h
289289

290290
# Opening boilerplate for schemapg.h
291-
print SCHEMAPG <<EOM;
291+
print $schemapg <<EOM;
292292
/*-------------------------------------------------------------------------
293293
*
294294
* schemapg.h
@@ -313,19 +313,19 @@
313313
# Emit schemapg declarations
314314
foreach my $table_name (@tables_needing_macros)
315315
{
316-
print SCHEMAPG "\n#define Schema_$table_name \\\n";
317-
print SCHEMAPG join ", \\\n", @{ $schemapg_entries{$table_name} };
318-
print SCHEMAPG "\n";
316+
print $schemapg "\n#define Schema_$table_name \\\n";
317+
print $schemapg join ", \\\n", @{ $schemapg_entries{$table_name} };
318+
print $schemapg "\n";
319319
}
320320

321321
# Closing boilerplate for schemapg.h
322-
print SCHEMAPG "\n#endif /* SCHEMAPG_H */\n";
322+
print $schemapg "\n#endif /* SCHEMAPG_H */\n";
323323

324324
# We're done emitting data
325-
close BKI;
326-
close SCHEMAPG;
327-
close DESCR;
328-
close SHDESCR;
325+
close $bki;
326+
close $schemapg;
327+
close $descr;
328+
close $shdescr;
329329

330330
# Finally, rename the completed files into place.
331331
Catalog::RenameTempFile($bkifile, $tmpext);
@@ -425,7 +425,7 @@ sub bki_insert
425425
my @attnames = @_;
426426
my $oid = $row->{oid} ? "OID = $row->{oid} " : '';
427427
my $bki_values = join ' ', map $row->{$_}, @attnames;
428-
printf BKI "insert %s( %s)\n", $oid, $bki_values;
428+
printf $bki "insert %s( %s)\n", $oid, $bki_values;
429429
}
430430

431431
# The field values of a Schema_pg_xxx declaration are similar, but not
@@ -472,15 +472,15 @@ sub find_defined_symbol
472472
}
473473
my $file = $path . $catalog_header;
474474
next if !-f $file;
475-
open(FIND_DEFINED_SYMBOL, '<', $file) || die "$file: $!";
476-
while (<FIND_DEFINED_SYMBOL>)
475+
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
476+
while (<$find_defined_symbol>)
477477
{
478478
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
479479
{
480480
return $1;
481481
}
482482
}
483-
close FIND_DEFINED_SYMBOL;
483+
close $find_defined_symbol;
484484
die "$file: no definition found for $symbol\n";
485485
}
486486
die "$catalog_header: not found in any include directory\n";

0 commit comments

Comments
 (0)