Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

FileCache Usage

by loris (Hermit)
on Feb 09, 2007 at 09:33 UTC ( #599177=perlquestion: print w/ replies, xml ) Need Help??
loris has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I assume I am being dopey, but I don't understand why this

my $fh; open($fh,'<',$file); while (<$fh>) { print "line: $_\n"; }

is OK, whereas this

my $fh; $fh = cacheout('<',$file); while (<$fh>) { print "line: $_\n"; }

tells me

readline() on unopened filehandle 1 at ... readline() on unopened filehandle 2 at ... readline() on unopened filehandle 3 at ... ...

Can someone please enlighten me?

Update: I'm using Perl 5.8.0 on solaris.

Thanks,

loris


"It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ." (from "Slow Loris" by Alexis Deacon)

Comment on FileCache Usage
Select or Download Code
Re: FileCache Usage
by Corion (Pope) on Feb 09, 2007 at 09:48 UTC

    Most likely because cacheout, whatever that is, returns undef instead an opened filehandle. Check that:

    die "Didn't get a sensible result from cacheout() for '$file'. Maybe t +his helps: $!" unless $fh;

    Looking closer at your error message and the increasing number of filehandles, it seems that cacheout() returns a fileno and not something that Perl considers a valid, open filehandle. The error is likely in cacheout().

    Looking closer at your topic I now realize you're talking about FileCache, stupid me.

    Looking even closer, I can't replicate your problem:

    Q:\>type test.txt 1 2 3 Q:\>perl -MFileCache -le "my $fh = cacheout('<','test.txt'); print for + <$fh>" 1 2 3 Q:\>perl -MFileCache -le "my $fh = cacheout('<','does-not-exist.txt'); + print for <$fh>" Can't create does-not-exist.txt: No such file or directory at -e line +1

    So maybe the file exists but you don't have read permissions? This is on Win32, Perl 5.8.2, stock FileCache

      The file does exist and is readable. Otherwise the open version wouldn't work either, would it?

      Thanks,

      loris


      "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ." (from "Slow Loris" by Alexis Deacon)
Re: FileCache Usage
by PreferredUserName (Pilgrim) on Feb 09, 2007 at 16:13 UTC
    You should always say: "open(...) or die $!", or in your case "cacheout(...) or die $!".

    You can't just assume that open() worked, as it frequently does not.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://599177]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-11-27 17:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (186 votes), past polls