Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

jar like feature

by podian (Scribe)
on Sep 21, 2004 at 18:29 UTC ( #392727=perlquestion: print w/replies, xml ) Need Help??
podian has asked for the wisdom of the Perl Monks concerning the following question:

I am developing a GUI using perl/Tk and wondering how I can bundle stuff into one file like Java's jar file. For example, in my application, I have two GIF files, three modules (pm files) and one PDF file. It would be nice if I can bundle all of them into one file and invoke it like this
perl -jar myfile.jar
the reason I am asking this is that if I invoke my application from a different directory, it is not finding my GIF files unless I attach the absolute path to it in my code
my $logo = $main->Photo(-file=>"$dir/samsunglogo.gif");
I can't just say
my $logo = $main->Photo(-file=>"samsunglogo.gif");
and let my application find the file!

Replies are listed 'Best First'.
Re: jar like feature
by rjbs (Pilgrim) on Sep 21, 2004 at 18:42 UTC
    The best-fit for this is, not surprisingly, PAR. It's like JAR, with a P instead of a J.

    PAR at CPAN has PAR::Tutorial to walk you through using PAR.
      Also not surprisingly, Par-Par is much better-liked than Jar-Jar in *ar Wars. (pronounced "Star-ar Wars")

      Caution: Contents may have been coded under pressure.
      I have noticed that PAR is not exactly stable yet. Not every GUI application can be simply PAR'ed up. I still get several emails a week from the PAR mailing list regarding some problem or another. If PAR works for you, great! If it doesn't, you may have to struggle with it for a while to achieve the desired effect.
Re: jar like feature
by ikegami (Pope) on Sep 21, 2004 at 19:21 UTC

    You could do:

    # use File::Spec if you want to be more portable. # The following supports at least unix and Windows. $dir = ($0 =~ m#^(.*[\\/:])# ? $1 : ''); my $logo = $main->Photo(-file=>$dir."samsunglogo.gif");


    # use File::Spec if you want to be more portable. # The following supports at least unix and Windows. chdir($1) if ($0 =~ m#^(.*[\\/:])#); my $logo = $main->Photo(-file=>"samsunglogo.gif");
      I just tested, and $0 works on Mac (MacPerl), so it's probably good across all platforms.
        I wasn't refering to $0, but to the path seperator. In unix, it's '/'. In Windows, it can be '\' and ':'. I don't know about other OSs. File::Spec contains functions to parse paths, but I was too lazy to lookup the syntax.
Re: jar like feature
by eyepopslikeamosquito (Chancellor) on Sep 21, 2004 at 23:19 UTC
    I have two GIF files, three modules (pm files)...
    If the GIF files are in a known location relative to the .pm file, you could use Perl's __FILE__ variable in the .pm file. For example, in the Photo method, if a bald file name is given, you could look for that file in a directory relative to the .pm file (that trick is used by Acme::EyeDrops to find the .eye files relative to
Re: jar like feature
by chb (Deacon) on Sep 22, 2004 at 05:48 UTC
    Use the FindBin core module to get rid of absolute paths. From the docs: "Locates the full path to the script bin directory to allow the use of paths relative to the bin directory."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://392727]
Approved by talexb
Front-paged by been42
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-01-23 00:22 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (238 votes). Check out past polls.