Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created February 25, 2009 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagolden/69940 to your computer and use it in GitHub Desktop.
Save dagolden/69940 to your computer and use it in GitHub Desktop.
perl require bug?
# with STDIN closed, $Config{$var} leaves the STDIN fd open
$ perl -MConfig -wE 'close STDIN; open my $fh, "</dev/null"; say fileno $fh; close $fh; say $Config{d_fork}; open $fh, "</dev/null"; say fileno $fh; close $fh'
0
define
3
# with STDIN as normal, $Config{$var} doesn't leak an fd
$ perl -MConfig -wE 'open my $fh, "</dev/null"; say fileno $fh; close $fh; say $Config{d_fork}; open $fh, "</dev/null"; say fileno $fh; close $fh'
3
define
3
# the issue seems to be the 'require' statement when STDIN is closed
$ perl -wE 'close STDIN; open my $fh, "</dev/null"; say fileno $fh; close $fh; require "Config_heavy.pl"; open $fh, "</dev/null"; say fileno $fh; close $fh'
0
3
# another example of 'require' with STDIN closed
$ perl -wE 'close STDIN; open my $fh, "</dev/null"; say fileno $fh; close $fh; require File::Temp; open $fh, "</dev/null"; say fileno $fh; close $fh'
0
3
# an example of require with STDIN normal
$ perl -wE 'open my $fh, "</dev/null"; say fileno $fh; close $fh; require File::Temp; open $fh, "</dev/null"; say fileno $fh; close $fh'
3
3
# an example without require with STDIN as usual
$ perl -MConfig -wE 'open my $fh, "</dev/null"; say fileno $fh; close $fh; ; open $fh, "</dev/null"; say fileno $fh; close $fh'
3
3
# an example without require with STDIN closed
$ perl -MConfig -wE 'close STDIN; open my $fh, "</dev/null"; say fileno $fh; close $fh; ; open $fh, "</dev/null"; say fileno $fh; close $fh'
0
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment