Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Inline::Files unopened filehandle errors redux

by NateTut (Deacon)
on Oct 16, 2009 at 21:32 UTC ( #801658=perlquestion: print w/ replies, xml ) Need Help??
NateTut has asked for the wisdom of the Perl Monks concerning the following question:

Well it's late on a Friday and I'm stuck. I'm trying to get Inline::Files to work and I am frustrated. I have boiled it down to the example below. Basically if you read from the virtual file and then try to write to it you get:

print() on unopened filehandle CONFIG at Change__DATA__.pl line 26.

Otherwise it works as advertized. I have tried it on Windoze & Solaris with the same results.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Inline::Files -backup; my $Config; if(defined($ARGV[0]) and $ARGV[0] eq 'NoRead') { $Config->{'Foo'} = 1; } else { $Config = eval join "", <CONFIG>; } local $Data::Dumper::Useqq = 1; local $Data::Dumper::Indent = 1; $Config->{'Foo'}++; print Data::Dumper->Dump([$Config],['Config']); seek CONFIG, 0, 0; print CONFIG Data::Dumper->Dump([$Config],['Config']); __CONFIG__ $Config = { "Foo" => 2 };

Comment on Inline::Files unopened filehandle errors redux
Select or Download Code
Re: Inline::Files unopened filehandle errors redux
by BrowserUk (Pope) on Oct 16, 2009 at 21:56 UTC

    Your question is answered (obliquely) by reading the section of the POD entitled "Writable virtual files".

    By default, the virtual files are opened in readonly mode, and when you read past the EOF, they are closed. It is not enough to just rewind (seek FILE, 0, 0;), you also need to re-open the file for write or read-write access.

    This is not a complete answer, The affect of the above is to cause multiple __CONFIG__ sections to be written. I think that is a bug. I think the module suffers a severe lack of maintenance.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I saw that, but when I try to re-open the virtual file I get:

      Variable "$CONFIG" is not imported at Change__DATA__.pl line 25. Global symbol "$CONFIG" requires explicit package name at Change__DATA +__.pl line 25. Execution of Change__DATA__.pl aborted due to compilation errors.

      I have tried various tricks to get it to open to no avail. The weird thing is that if it only reads one line you can still write.
        but when I try to re-open the virtual file I get: Variable "$CONFIG" is not imported

        Yes. That's what I get with 5.10 also. It never used to happen. From mmeory, it worked correctly circa 5.8.1|2|4|5'ish. But my memory is fallible and I don't have the capacity to test that aassertion.

        I tried adding our $CONFIG; at the top of the file and that changes the problem to:

        Use of uninitialized value $CONFIG in concatenation (.) or string

        But doesn't fix it entirley.

        Like I said, I think that it suffers from a lack of ongoing maintenance. As with s many of theDamian's modules.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (16)
As of 2014-07-28 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (204 votes), past polls