Gossamer Forum
Home : General : Perl Programming :

Requiring/BEGIN

Quote Reply
Requiring/BEGIN
Sigh, I have my tar module WO::Tar and when I require it into my script and read a tar it all works fine but as soon as I try to use the following:

{
BEGIN { $INC{"WO/Tar.pm"} = "WO/Tar.pm" }
my code here
}

.....(modelled after GT's install.cgi script) I get the folowing error:

substr outside of string at e:\apache\cgi-bin\install\file.cgi line 624.

That line is:

# Verify the checksum.
substr($head,148,8) = " ";

...I can't really see why that would cause an error using BEGIN...perldoc says:

If OFFSET and LENGTH specify a substring that is partly outside the string, only the part within the string is returned. If the substring is beyond either end of the string, substr() returns the undefined value and produces a warning. When used as an lvalue, specifying a substring that is entirely outside the string is a fatal error.

What can I do to fix that?....and why it it only happening with BEGIN?

Last edited by:

Paul: Jul 28, 2002, 10:27 AM
Quote Reply
Re: [Paul] Requiring/BEGIN In reply to
Fixed Laugh

Using a BEGIN block within the cgi script to compile WO::Tar meant that some of my global vars weren't activating, I had to put them inside a BEGIN block too in WO::Tar for them to be defined.