in reply to 'strict refs' + 'strict sub' = suck.

I dont know what's going on. Keep in mind that this is within a sub, though, the reason strict sub is giving an error. This is the actual code I'm using, it gets a line-delimited list of images from file to keep from wasting sql queries.

#--GETAVATARS--# sub getavatars { my $id = $_[0]; my $filename = "./avatars/$id/avatar.dat"; open (FILE, "$filename"); my @avatars = <FILE>; close(FILE); return(FILE); }
and this is the error I get:

Content-type: text/html ERROR Bareword "FILE" not allowed while "strict subs" in use at ./modules/ad +min/users.cgi line 161. Compilation failed in require at admin.cgi li +ne 54.

Replies are listed 'Best First'.
Re: Re: 'strict refs' + 'strict sub' = suck.
by liz (Monsignor) on Oct 24, 2003 at 20:51 UTC
    Why would you want to return a closed file handle?

    return(FILE);

    That's the line causing the error. I'm not sure what that subroutine is supposed to do, as it is reading the file into a lexical array, local to the subroutine, and not doing anything with it afterwards. Maybe you want to:

    return @avatars;
    or:
    return \@avatars;

    ?

    Liz

Re: Re: 'strict refs' + 'strict sub' = suck.
by toonski (Beadle) on Oct 24, 2003 at 20:47 UTC
    EDIT: Oh my god, I see the error. I'm not sure why I put "return(FILE), but that's apparently what's causing it. Thanks for your help :)

      Incidentally, if you really meant to return the close handle you would either have used IO::File in the first place or you'd return the glob ala return \*FILE;.

      I guess you need to figure out how to go to specified line numbers in the text editor that you use for perl programming. When perl reports an error at a specific line number, the first thing to try is to go directly to that line number in the file.