testing for existence of an inline file with Inline::Files

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I'm using Inline::Files, which allows me to put data after __FOO__ in
a file and then to read it with "while (<FOO>) " or @lines =

This works fine as long as there is such a section defined.  However,
I haven't been able to figure out how to check whether such a section
exists in the first place.  Say I have the name of a possible section
in $sec, e.g.
   $sec = 'main::MYCANDIDATE';
If I just go ahead with
   @lines = <$sec>;
I get a read-from-unopened-filehandle error if there is no section
__MYCANDIDATE__ in the script.  This works fine if the section

Can someone suggest a test to apply before attempting to read?

Things I've tried:
   open IN, "<$sec" or ...;
which doesn't work because $sec itself is the (indirect) filehandle.
   open $sec or ...;
   open sec or ...;
both also didn't work.  Both fail even if the section appears.
   no strict refs;
   my $cand = 'MYCANDIDATE';
   if (exists $) { ... }
   # or: if (exists $main::) { ... }
gives the mysterious "unknown error" at runtime, though the Perl
Cookbook says that there should be a hash %MYCANDIDATE with data about
the handle to the inline file, in particular a key "file".

I have a workaround which requires users in effect to declare the
sections first, but I'd like to understand this better.

Site Timeline