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

I'm trying to use pp to build an executable that contains a data file from which it reads.

Here's the command I'm using:

pp -v=3 -a /Users/chap/private/dict/lex.dict -o ppdir/brillig brillig

Verbose output includes the line:

adding /Users/chap/private/dict/lex.dict as Users/chap/private/dict/lex.dict
The pp documentation of the -a switch is as follows:
-a, --addfile=FILE|DIR Add an extra file into the package. If the file is a directory, recursively add all files inside that directory, with links turned into actual files.

By default, files are placed under / inside the package with their original names. You may override this by appending the target filename after a ; like this: % pp -a "old_filename.txt;new_filename.txt"

I don't understand the bolded sentence. What path should my Perl code use to access lex.dict?


Replies are listed 'Best First'.
Re: pp (PAR-Packer) - how to access included data files
by marto (Cardinal) on Nov 06, 2022 at 20:48 UTC
Re: pp (PAR-Packer) - how to access included data files
by bliako (Abbot) on Nov 06, 2022 at 22:32 UTC
Re: pp (PAR-Packer) - how to access included data files
by swl (Parson) on Nov 06, 2022 at 21:35 UTC
      I wasn't really clear about the use of PAR_TEMP, given the advice not to use it in .

      I finally figured out that "/", which the doc says is the root under which included files are stored, could be computed at runtime by dirname($ENV{PAR_0}) . "/inc".

        dirname($ENV{PAR_0}) . "/inc".

        Why you want to go low level when you have this? :

        # PAR::read_file() returns a file inside any loaded PARs my $conf = PAR::read_file('data/MyConfig.yaml');

        (from SYNOPSIS)

        The docs could be a bit clearer but my reading is that PAR_TEMP should not be assigned to but is fine to read from.

        Your approach will still work, though.

Re: pp (PAR-Packer) - how to access included data files
by sectokia (Pilgrim) on Nov 09, 2022 at 02:28 UTC

    If you want to get the contents of the file simply do this in your pl program:

    use PAR; my $fileData = PAR::read_file('lex.dict');

    I believe this is the only real guaranteed way to get the file data. All other ways would be assuming things about how par unpacks and/or uses temp files, and/or enviroment variables, which are subject to change.