perl_seeker has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I have been trying to create an exe file of a Perl script and am using PerlApp which comes with ActiveState's PDK 5.0.

I'm using PerlApp to pack a .pl file along with text files and .pm's
perlapp myscript.pl --add mypm.pm --bind mytextfile.txt[text,extract,f +ile=c:\test,mode=0777] --tmpdir c:\mycurrentdir
Suppose we set the --tmpdir option to the current folder in which we have the .exe file.Once we run the .exe file,
the text files packed with the .exe get extracted in a temp folder inside the current folder in this way:
c:\mycurrentdir\pdk-username-856877
the process id gets appended to the folder name.So my .pl script cant find the text files , since it searches only
the current folder and not any sub folders inside it.

Suppose I use stmts like this to open mytextfile.txt in myscript.pl
open TF,'>mytextfile.txt' or die $!;
Can we make the .pl script search for mytextfile.txt in all sub folders inside the current folder as well(mycurrentdir)
instead of just searching the current folder?
Thanks in advance.
:)

Replies are listed 'Best First'.
Re: Perl App , files and directories
by Art_XIV (Hermit) on Nov 03, 2003 at 13:24 UTC

    I'm not sure that I really understand the issue, but the modules Cwd and/or File::Find might be able to help.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
      Hello,
      thanks for the reply. I'm reading up on File:Find
      :)
Re: Perl App , files and directories
by jand (Friar) on Nov 04, 2003 at 02:09 UTC
    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.

      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.
      :)