Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

How to Teach artists Perl w/out Modules

by teknomage1 (Initiate)
on Jan 30, 2004 at 21:07 UTC ( #325397=perlquestion: print w/replies, xml ) Need Help??

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

So here's the situation: I've been asked by a professor to write a perl image compositing script that he can use to teach his class of artists some basic perl commands/syntax. There are only two problems; a)I've only been using perl for a month and a half and b)we can't install any modules because of current tech. policy. I guess i can figure out where to go once I get the file read in but I don't know how to go about reading in a .tga (Targa) file. I'm sorry if this is a stupid question but I don't know what to do.
  • Comment on How to Teach artists Perl w/out Modules

Replies are listed 'Best First'.
Re: How to Teach artists Perl w/out Modules
by flyingmoose (Priest) on Jan 30, 2004 at 21:42 UTC

    I would not just copy and paste the code you need. Create a local directory on your machine and save the CPAN files (which should be available in an archive format) on your hard drive or locker space or whatever is the easiest. Most universities with Unix systems can create public lockers that users can mount, or maybe you can share this in your home directory for others to use.

    Then towards the top of the file

    use lib "/path/to/mycpan";

    You will be able to use most, if not all, modules as if you had installed them through the normal convention.

    A good module to use might be GD

      flyingmoose wrote:
      I would not just copy and paste the code you need. Create a local directory on your machine and save the CPAN files (which should be available in an archive format) on your hard drive or locker space or whatever is the easiest.

      Right. This is the right answer nearly all the time, I think. In this case particularly, modules that deal with images are very complex, usually use xsubs, and so on. Cutting-and-pasting is not likely to work out well.

      One question I have (for the OP) is "why targa (.tga)?" That's one of the odder and more difficult formats to work with. GD supports PNG (IMHO, the best format for this case), JPEG and so forth, and PerlMagick/ supports .tga and many others, but is much more difficult to install than GD. For starters I would recommend working in the PNG format, doing any pre-conversion of .tga to .png necessary.

          Soren A / somian / perlspinr / Intrepid

      Cynicism is not "cool" or "hip" or "intelligent". It's like Saddam Hussein's piss mixed
      with 004 grit and nitric acid. It's corrosive to everything it touches, destructive to
      human endeavors, foul and disgusting. And ultimately will eat away the insides of the
      person who nurtures it.
      Create a local directory on your machine and save the CPAN files (which should be available in an archive format) on your hard drive or locker space or whatever is the easiest.

      ohh, this is a horrible way to do things. I know I've done this and would not recommend it. Why? CPAN modules are built much like LEGO. A lot of the image modules may be built upon other modules. So you require all the parent modules of the module you choose.

      I had to use this method (no net connection) to download, install a complex system using many CPAN modules. Downloading and installing by hand is bad, frustrating and slow.

        ... unless you want to waste a whole afternoon or evening, find an alternative.

      What system are you using? (Windows? - Can you install Cygwin?) or Do you have access to a laptop with net access so you can install the CPAN modules. Using CPAN to download modules is good.

        CPAN -e
        ls AUTHORNAME

      At least you can use the systems side by side with the possibility of transferring working code from the laptop to target machine.

        It's linux w/ a non persistant home directory, ie. they delete whatever's in our homespce every night so we have to back up stuff onto cds. To make matters worse the school's tech policy was written in the windoews days and explicitly states no executables of any form should be installed.
Re: How to Teach artists Perl w/out Modules
by Sol-Invictus (Scribe) on Jan 31, 2004 at 15:07 UTC
    Under Linux/Unix you can install CPAN or any other module in your user account and run it from there. If you don't have much diskspace you can just install the modules you need, though dependencies can make life awkward (see the trouble shooting section). Installing perl modules is fairly straight forward:

    1. make a site_perl folder somewhere in your user account :

    [SHELL PROMPT ]$ mkdir site_perl

    2. set the environment variable PERL5LIB :

    [SHELL PROMPT ]$ cd ~ # check for shell configuration files [SHELL PROMPT ]$ ls -al (for sh, bash, ksh, or zsh shells - example used: bash) [SHELL PROMPT ]$ pico ./.bashrc [PICO PROMPT ]$ export PERL5LIB=$HOME/path/to/my/site_perl (for csh or tcsh shells - example used tcsh) [SHELL PROMPT ]$ pico ./.cshrc [PICO PROMPT ]$ set PERL5LIB=/path/to/my/site_perl

    you can check if it's set correctly by typing:


    This only affects the Environment variables of the shell, not the system, so you may have to logout and re-login in before the new path will become active. If the echo command still doesn't seem to print anything, or, if it prints something different from what you typed even after logging out and in, then the variable hasn't been set correctly. Repeat the last few steps again to set the new path.

    3. FTP the module into your site_perl folder

    [SHELL PROMPT ]$ cd /path/to/your/site_perl [SHELL PROMPT ]$ ftp login: anonymous ftp> get /path/to/yourmodule.tar.gz [space]/path/to/your/site_perl/yo +urmodule.tar.gz ftp> quit 221 Goodbye.

    4. DECOMPRESS the file:

    [SHELL PROMPT ]$ gzip -d yourmodule.tar.gz

    5. UNPACK the file :

    [SHELL PROMPT ]$ tar -xvf yourmodule.tar
    6. BUILD the module (sometimes unnecessary):

    [SHELL PROMPT ]$ perl Makefile.PL LIB=/path/to/my/site_perl \ INSTALLMAN1DIR=/path/to/my/man/man1 \ INSTALLMAN3DIR=/path/to/my/man/man3 [SHELL PROMPT ]$ make [SHELL PROMPT ]$ make test

    7. INSTALL the module:

    [SHELL PROMPT ]$ make install
    8. Troubleshooting:

    If you get errors about a file not being created:

    i. create the path to the file as it was written in the error
    ii. install again.

    If the error says a module is missing - this is caused by dependancy, in other words the module you want uses another module:

    i. FTP the missing module from into your site_perl folder as before
    ii. go through the installation process as before.

    After installation, in your scripts and cgis, insert the line (perl versions 5.002 and later):

    use lib '/path/to/my/site_perl';
    or for earlier perls (5.001 and before):

    BEGIN { unshift(@INC, "/path/to/my/site_perl") }

    so the perl interpreter will know to check your site_perl dir for modules.

    Installing was designed to free you out from the circular hell of dependancy. Follow the installation procedure as above, once installed and you've checked that the path to your site_perl folder is set correctly in the ENVIRONMENT variables you can start up the CPAN shell by typing:

    [SHELL PROMPT ]$ perl -MCPAN -e shell

    the first time you run it you'll be prompted for config info, in most cases the default values are fine (just press enter without writing anything), but you must make sure you set the following two correctly for either, or any modules it installs, to work correctly:

    cpan> cpan_home: /path/to/my/site_perl/ANY_NAME_YOU_WANT cpan> makepl_arg: LIB=/path/to/my/site_perl you can check these values in the CPAN shell at any time by typing: cpan> o conf
    which outputs a listing of all the config variables* similar to this:

    cpan> o conf CPAN::Config options and /Users/Sol-Invictus/site-perl/.cpan/CPAN/MyCo commit Commit changes to disk defaults Reload defaults from disk init Interactive setting of all options build_cache 10 build_dir /Users/Sol-Invictus/site-perl/.cpan/build cache_metadata 1 cpan_home /Users/Sol-Invictus/site-perl/.cpan dontload_hash ftp /usr/bin/ftp ftp_proxy getcwd cwd gzip /usr/bin/gzip histfile /Users/Sol-Invictus/site-perl/.cpan/histfile histsize 100 http_proxy inactivity_timeout 0 index_expire 1 inhibit_startup_message 0 keep_source_where /Users/Sol-Invictus/site-perl/.cpan/sources lynx make /usr/bin/make make_arg make_install_arg makepl_arg ncftp ncftpget no_proxy pager /usr/bin/less prerequisites_policy ask scan_cache atstart shell /bin/tcsh tar /usr/bin/tar term_is_latin 1 unzip /usr/bin/unzip urllist wait_list wait:// wget

    *note: the first 3 are commands

    To run this config script again at any time type (in the CPAN shell):

    cpan> o conf init

    See the relevant MAN page or PODs for more information on how to set or unset these variables individually, either:

    [SHELL PROMPT]$ perldoc CPAN



    Once installed correctly, adding other modules to your site_perl becomes a breeze - just type:

    [SHELL PROMPT ]$ perl -MCPAN -e shell cpan> install MODULE_YOU_WANT

    and does the rest (including installing any other fish hooked modules). Equally as useful, through CPAN you can check for newer releases of existing modules and automatically install them as they become available, much like a package management system. For a brief summary of's commands use the CPAN shell's own internal help function:

    cpan> ?
Re: How to Teach artists Perl w/out Modules
by cees (Curate) on Jan 31, 2004 at 01:20 UTC

    If you want to do a lot of work with images and don't want to use external modules, then can I suggest you find a targa to pbm (portable bit map) converter so that you can work with the images in pbm format (or ppm if you want color as well). That is about the simplest image format available, and is very easy to manipulate with straight perl.

    I am pretty sure that the netpbm package comes with a pbmtotga and tgatopbm program to do the conversion for you.

    Here is a description of the ppm image format:

Re: How to Teach artists Perl w/out Modules
by hardburn (Abbot) on Jan 30, 2004 at 21:37 UTC

    Grab the module off CPAN and cut-and-paste the code you need.

    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

      Doh! I guess i was freaking out. At the very least i can poke around the modules and see how they read in files. What if the module is in C though?
Re: How to Teach artists Perl w/out Modules
by David Caughell (Monk) on Jan 30, 2004 at 21:56 UTC

    I ran into this problem at my college also.

    However, if you're allowed to put a module in your home directory, with your perl script, go ahead and do that, because when the use (directive?) is called, it checks the current (script's?) directory.

    You might be able to skate by them this time. :)


Re: How to Teach artists Perl w/out Modules
by CountZero (Bishop) on Jan 31, 2004 at 08:39 UTC
    Time to change the tech. policy.

    Such stupid policies are like trying to teach someone to drive a car, but the steering wheel has been removed and you may not install it, since steering wheels have caused a lot of chest injuries in the past.


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://325397]
Approved by xenchu
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-01-29 13:43 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (74 votes). Check out past polls.