in reply to Perl App , files and directories
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 |