Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

pp (PAR-Packer) - how to access included data files

by ibm1620 (Hermit)
on Nov 06, 2022 at 19:12 UTC ( [id://11148010]=perlquestion: print w/replies, xml ) Need Help??

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?

Thanks!

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 (Monsignor) 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 https://metacpan.org/dist/PAR/view/lib/PAR/Environment.pod .

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11148010]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-05-21 04:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found