in reply to Perl App , files and directories

Please read the documentation of PerlApp, or at least the docs about bundled functions:
    perlapp --help FUNCTIONS
It will tell you about PerlApp::extract_bound_file(FILENAME) and PerlApp::get_bound_file(FILENAME), which provide access to the bound data:
=head1 FUNCTIONS

The following functions are made available to the Perl program when
running from the executable that I<PerlApp> creates:

=over

=item B<PerlApp::exe()>

Returns the full path (including file name) to the running executable.

=item B<PerlApp::extract_bound_file(FILENAME)>

Writes the content of a bound file to the filesystem.  The file will be
created in a temporary directory and is automatically deleted when the
application terminates.  The function returns the filename of the
temporary file:

    my $datafile = "data.txt";
    my $filename = PerlApp::extract_bound_file($datafile);
    die "$datafile not bound to application\n" unless defined $filename;
    open(my $fh, $filename) or die "Can't open $datafile($filename)\n";

If the file had not been bound, C<extract_bound_file()> returns
C<undef>.

C<extract_bound_file()> always writes files in C<binmode>.  Therefore
files bound with the C<text> option on Windows will be extracted
with C<\n> and not C<\r\n> line endings.

=item B<PerlApp::get_bound_file(FILENAME)>

Returns the content of files included in the executable with the
C<--bind> commandline option.  Returns the whole file as
a single string in scalar context or separate lines in list context,
in which case lines are always split on newline (i.e. $/ is not
considered).

    foreach my $line (PerlApp::get_bound_file("data.txt")) {
        # ... process $line ...
    }

If the file had not been bound, C<get_bound_file()> returns
C<undef> in scalar context or the empty list in list context.

=back

In your sample code you open the file for writing, not reading. That doesn't make much sense because any changes to the file will not be stored back in the application itself. I assume it was just a typo.

Finally, you don't want to use the --tmpdir option unless you absolutely have to. It makes you application dependent on an absolute path value which cannot be changed later.

Replies are listed 'Best First'.
Re: Re: Perl App , files and directories
by perl_seeker (Scribe) on Nov 07, 2003 at 10:41 UTC
    Hello,
    thanks for the reply.I've read most of the PerlApp docs.I'm using code like this in my .pl
    sub chfile { ....... my $datafile = "myfile.txt"; my $filename = PerlApp::extract_bound_file($datafile); die "$datafile not bound to application\n" unless defined $filename; my $fh="LEX"; open($fh,'$filename') or die "Can't open $datafile $filename)\n"; while(<LEX>){ ...... } }
    When I create the .exe using PerlApp(I've set --tmpdir to c:\test for the time being) and run it , the exe cannot
    open myfile.txt. I keep getting this error:
    Tk:Error:Can't open myfile.txt <c:\test\pdk-myname--121077199/myfile.t +xt>[\&main::chfile]
    What am I doing wrong here? Please help!

    Also, I need to write(append words) to myfile.txt when the application is running.I need the .exe to use the
    updated version of myfile.txt(with new words appended in the last run) the next time it is invoked.
    Is this not possible with PerlApp?
    Thanks in advance.
    :)