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

Hi monks !

I found the explanation of a bug but don't know how to resolve it !!

I'm using a perl API from ensembl (it's an API to deal with the genomic annotation of genomes) and for each release of the ensembl database, they release a new API that reflects changes in the DB structure, so your code still works.
In brief, you HAVE TO use the same API version as the genome version you want to use.

In my case, i want to offer to the user the choice of the genome version to use. A form is posted to my script, and then i was trying to do something like that :
my $version = "something from the post" use lib "/commun_path/$verion/ensembl/modules"; use Bio::EnsEMBL::Registry;
Of course, that doesn't work because $version isn't initialized at compile time. But I can't get the version from the post before runtime, so is there a way to do that ?
Thanks,

Marcel

Replies are listed 'Best First'.
Re: dealing with RUNTIME, COMPILE TIME and use lib ...
by davorg (Chancellor) on Aug 23, 2006 at 13:22 UTC

    Switch to using equivalent code that executes at runtime.

    my $version = "something from the post" unshift @INC, "/commun_path/$version/ensembl/modules"; require Bio::EnsEMBL::Registry; Bio::EnsEMBL::Registry->import;
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Or run your code during compile time

      my $version; BEGIN { $version = "something from the post"; } use lib "/commun_path/$version/ensembl/modules"; use Bio::EnsEMBL::Registry;

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        I thought about that. But then I thought that

        $version = "something from the post";

        could potentially involve all sorts of complexities that you might not want to do at compile time.

        It's certainly another alternative tho'.

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

Re: dealing with RUNTIME, COMPILE TIME and use lib ...
by rir (Vicar) on Aug 23, 2006 at 14:05 UTC
    This is what BEGIN and CHECK are intended to handle. To keep your code clear I'd suggest requiring your main program. If you want more control than require allows, look at the require doc's--they give implementation code. Partitioning the code like this is not necessary, but the nature of the problem (interactive and controlled by third party) suggest a conservative approach.

    Be well,
    rir

    #!/usr/bin/perl use strict; use warnings; BEGIN { print "Begin code$/Get initialization info from user$/"; }
    Update: Added next line, which was rather the point of partitioning the code.
    print "Or do initialization here before the require$/"; require Program; END { print "End program$/"; }
    Progam.plpm
    package Program; BEGIN: { print "Begin module$/initialize$/" } print "Runtime$/"; END: { print "End module$/" } 1;