CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=43200
server: Combust/Plack (Perl)
vary: Accept-Encoding
content-encoding: gzip
content-length: 2071
content-type: text/html; charset=utf-8
last-modified: Tue, 14 Oct 2025 08:07:07 GMT
date: Tue, 14 Oct 2025 08:07:07 GMT
strict-transport-security: max-age=15768000
[perl #56954] Valid syntax provided by @INC import hook is misparsed - nntp.perl.org
Front page | perl.perl5.porters |
Postings from July 2008
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About

[perl #56954] Valid syntax provided by @INC import hook is misparsed
From:
Bram via RTDate:
July 27, 2008 10:57Subject:
[perl #56954] Valid syntax provided by @INC import hook is misparsedMessage ID:
rt-3.6.HEAD-29762-1217101232-1818.56954-15-0@perl.orgOn Tue Jul 15 08:51:19 2008, dheringt wrote: > This is a bug report for perl from herington_dean@emc.com, > > generated with the help of perlbug 1.35 running under perl v5.8.5. > > > > The attached program uses an @INC import hook to make two simple > > modules available from text in the program itself. > > `require Mod2` fails with: > > > > Missing right curly or square bracket at /loader/0x94ffc20/Mod2.pm > line 7, at end of line > > syntax error at /loader/0x94ffc20/Mod2.pm line 7, at EOF > > Compilation failed in require at INC-sub-bug line 47. > > > > even though module Mod2 is well-formed Perl code. Note that > > `require Mod1` succeeds, even though there is only a slight syntactic > > difference between the two modules. > If writing a temporary file isn't a problem then you can use the following hook: (which works on perl-5.6.0 - perl-current) unshift @INC, sub { my ($self, $path) = @_; if (exists $files{$path}) { my ($file) = $path =~ m#([^/]+)$#; $INC{$path} = "/foo/bar/baz"; my $t = "/tmp/perl_${file}_$$"; open my $fh, ">", $t or die "Can't open file: $!"; print $fh $files{$path}; close $fh; open my $fh2, "<", $t or die "Can't open file: $!"; return ($fh2, sub { if (not length $_) { close $fh2; unlink $t; } return length $_; }); } return; }; The 'normal' way would have been: #!/usr/bin/perl -wl use strict; my %files; $files{"Mod1.pm"} = <<'END'; package Mod1; sub subr { my ($path) = @_; open FH1, "<", $path or die; } 1; END $files{"Mod2.pm"} = <<'END'; package Mod2; sub subr { my ($path) = @_; open FH2, "<", $path or die; } 1; END unshift @INC, sub { my ($self, $path) = @_; if (exists $files{$path}) { $INC{$path} = "/foo/bar/baz"; my @lines = split /\n/, $files{$path}; my $i = 0; return (sub { if ($i >= @lines) { return 0; } $_ = $lines[$i++]; return 1; }); } return; }; require Mod1; require Mod2; __END__ perl-5.6.0 rt-56954.pl Number found where operator expected at /loader/0x811024c/Mod1.pm line 10, near "1" (Missing semicolon on previous line?) syntax error at /loader/0x811024c/Mod1.pm line 10, near "1" Missing right curly or square bracket at /loader/0x811024c/Mod1.pm line 10, at end of line Compilation failed in require at rt-56954.pl line 51. perl-5.8.8 rt-56954.pl Number found where operator expected at /loader/0x812c98c/Mod1.pm line 10, near "1" (Missing semicolon on previous line?) syntax error at /loader/0x812c98c/Mod1.pm line 10, near "1" Missing right curly or square bracket at /loader/0x812c98c/Mod1.pm line 10, at end of line Compilation failed in require at rt-56954.pl line 51. perl-5.8.9-tobe rt-56954.pl (no output - good) perl-5.10.0 rt-56954.pl (no output - good) perl-blead rt-56954.pl (no output - good) Kind regards, Bram
- [perl #56954] Valid syntax provided by @INC import hook is misparsed by Bram via RT
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About