Professional Web Applications Themes

Modules - PERL Beginners

Hi, I have a subroutine which is used by 2 programs. I want to make that subroutine a module. The subroutine uses some variables which i have declared in my main program. I am not able to pass those variable to my module. The subroutine is given below: The variables $base_files_used$exp_string and $base_files_to_remove$exp_string are declared in my main function. How should i call those two variables in my module? I have the same 2 variables declared in my other program which uses different values. Any help will be greatly appreciated. sub note_file_for_tarball { if ( 2 != _ ) { ...

  1. #1

    Default Modules

    Hi,

    I have a subroutine which is used by 2 programs. I want to make that
    subroutine a module. The subroutine uses some variables which i have
    declared in my main program. I am not able to pass those variable to my
    module. The subroutine is given below: The variables
    $base_files_used$exp_string and $base_files_to_remove$exp_string are
    declared in my main function. How should i call those two variables in my
    module? I have the same 2 variables declared in my other program which uses
    different values. Any help will be greatly appreciated.

    sub note_file_for_tarball {
    if ( 2 != _ ) {
    die "Wrong number of arguments to note_file_for_tarball.
    Dying at ";
    }
    my $filename = $_[0];
    my $to_be_removed = $_[1];

    my $file_log = "$base_files_used$exp_string";
    my $remove_log = "$base_files_to_remove$exp_string";

    open( FILE_USE_LOG, ">> $file_log" ) || die "Could not open
    $file_log for writing. Died at ";
    print FILE_USE_LOG "$filename\n";
    close( FILE_USE_LOG ) || die "Could not close $file_log. Died at ";

    if ( $to_be_removed ) {
    open( FILES_TO_REMOVE, ">> $remove_log" ) || die "Could not
    open $remove_log for writing. Died at ";
    print FILES_TO_REMOVE "$filename\n";
    close( FILES_TO_REMOVE ) || die "Could not close
    $remove_log. Died at ";
    }
    }


    Shilpa


    Shilpa Guest

  2. #2

    Default Re: modules

    I think so I am using Perl 5.8 and I never installed those modules manualy,
    but my scripts which uses those modules work just fine that means they comes
    with Perl.

    LRMK
    ----- Original Message -----
    From: "aditi gupta" <co.in>
    To: <org>
    Sent: Saturday, June 19, 2004 7:46 AM
    Subject: modules

     
    one has to separately install them? 

    Lrmk Guest

  3. #3

    Default modules

    All,

    I am unsure if I ed everyone off, b/c no one responded??? If I did I
    did not mean to my apologies.

    Anyway can anyone provide some insight?

    I am reading Object Oriented Perl pages 52 and 53 for setting up a module.
    It is telling me in order to use a routine from a different file you have
    to

    1) choose a lib directory
    2) export PERL5LIB=.../.../.../
    use lib /usr/local/perl/my.pl
    3) created nested subdirs for each component of the module name
    4) create a text file in the last directory
    5) Insert you code.
    6) add 1; at then end of the perl program file.


    NOTE: is says in the footer that I can use h2xs to combine steps 3 and 4.


    My quesiton is can't I just use step 2 and then in my program where I want
    to use this code, make a routine call?
    My goal is to set up a module for a routine that I can pass a data file
    to, from a different file so it can read this file in then execute.
    an example would be : &routine(datafile);



    I then looked into Perl Cookbook ch 12_02 and it discussed :


    In module file YourModule.pm, place the following code. Fill in the ellipses as explained in the
    Discussion section.
    package YourModule;
    use strict;
    use vars qw(ISA EXPORT EXPORT_OK %EXPORT_TAGS $VERSION);

    use Exporter;
    $VERSION = 1.00; # Or higher
    ISA = qw(Exporter);

    EXPORT = qw(...); # Symbols to autoexport (:DEFAULT tag)
    EXPORT_OK = qw(...); # Symbols to export on request
    %EXPORT_TAGS = ( # Define names for sets of symbols
    TAG1 => [...],
    TAG2 => [...],
    ...
    );

    ########################
    # your code goes here
    ########################

    1; # this should be your last line



    Is one autoloader and self loader? It seems to me I am getting
    conflicting info of just that I am not understanding?

    thank you,

    derek

    DBSMITH@OhioHealth.com Guest

  4. #4

    Default Re: modules

    On Thu, 30 Sep 2004 com wrote:
     

    Some (all?) of us have jobs and lives that occasionally prevent us from
    giving out free advice to strangers on the internet immediately.

    It happens.

    It isn't meant personally.
     

    What, and omit the other steps? Are they really that onerous?

    If you choose to put your module somewhere in the current INC, then
    steps 1 & 2 are taken care of, steps 3 & 4 are simply

    cd /usr/local/lib/perl
    mkdir -p Path/For/My/Deepest/Sub/Module
    echo "1;" > Path/For/My/Deepest/Sub/Module/stub.txt

    and then just write your code.

    Does this answer the question? I'm not clear what you're confused about.
     

    _Perl Cookbook_ is giving you the cookbook answer, suitable for cutting,
    pasting, and editing as needed.

    On the other hand, _Object Oriented Perl_ is trying to teach you to
    understand how OO *works* in Perl, including what steps are mandatory
    and which are optional and how different aspects can be implemented.

    Once you've digested Conway's book -- and you should finish with it,
    it's excellent -- then the section of the Cookbook should be clearer.



    --
    Chris Devers
    Chris Guest

  5. #5

    Default Re: modules

    Yes it does .... great thank you! But a few more things. Once I create
    my code, how do I pass a data file in a different program to a specific
    routine that lives in a different file?

    am I supposed to respond and post at the bottom of you answer?

    Derek B. Smith
    OhioHealth IT






    Chris Devers <com>
    09/30/2004 11:04 PM
    Please respond to Perl Beginners List


    To: com
    cc: Perl Beginners List <org>
    Subject: Re: modules


    On Thu, 30 Sep 2004 com wrote:
     

    Some (all?) of us have jobs and lives that occasionally prevent us from
    giving out free advice to strangers on the internet immediately.

    It happens.

    It isn't meant personally.
     
    4. 
    want 

    What, and omit the other steps? Are they really that onerous?

    If you choose to put your module somewhere in the current INC, then
    steps 1 & 2 are taken care of, steps 3 & 4 are simply

    cd /usr/local/lib/perl
    mkdir -p Path/For/My/Deepest/Sub/Module
    echo "1;" > Path/For/My/Deepest/Sub/Module/stub.txt

    and then just write your code.

    Does this answer the question? I'm not clear what you're confused about.
     

    _Perl Cookbook_ is giving you the cookbook answer, suitable for cutting,
    pasting, and editing as needed.

    On the other hand, _Object Oriented Perl_ is trying to teach you to
    understand how OO *works* in Perl, including what steps are mandatory
    and which are optional and how different aspects can be implemented.

    Once you've digested Conway's book -- and you should finish with it,
    it's excellent -- then the section of the Cookbook should be clearer.



    --
    Chris Devers



    DBSMITH@OhioHealth.com Guest

  6. #6

    Default Re: modules

    On Thu, 30 Sep 2004 com wrote:
     

    That's really up to you.

    You can have a way to pass the name of the file to that subroutine,
    which would then open & operate on it, or you could read in the file and
    pass the relevant contents to your routine. Which approach to take
    depends on how you want to design your system.

    I think I'd tend towards passing the file name and letting the method
    handle getting the data, but it's not a strong conviction, and in some
    cases I'd go about it in other ways.
     

    It's preferred, but I see that you're using Lotus Notes, and I've been
    forced to use Notes long enough -- about 90 seconds before I cried
    "uncle" -- to realize that it makes it really annoying to compose
    conventionally formatted emails.

    So in your case, from this account, don't worry about it too much.
    Getting Notes to do the right thing is too painful, and I sympathize.

    If you want to "do as the Romans do", maybe you can sign up for a Gmail
    account or something that would be more flexible...



    --
    Chris Devers
    Chris Guest

  7. #7

    Default Re: modules

    [snip] 
    Do u want to be one of the Romans? :-) Its hell good being Roman..
    Amongst many other things just to name a few advantage of being Roman are
    u almost never might need to delete messages and the contacts are
    pretty easy to get around, short cut key etc.. 1000 mb to use as ur
    own sec storage space. Its pretty good. I feel great! That pretty much
    explains why Romans ruled this world once. :)
    [snip] 



    --
    Cheers,
    SanoBabu
    Sano Guest

Similar Threads

  1. PHP & modules
    By Matthias Gutehall in forum Dreamweaver AppDev
    Replies: 1
    Last Post: March 29th, 04:29 PM
  2. Help in using Modules
    By Urvashi in forum PERL Beginners
    Replies: 4
    Last Post: April 8th, 02:20 PM
  3. where to look for modules?
    By Christopher J Bottaro in forum PERL Beginners
    Replies: 5
    Last Post: December 21st, 10:07 PM
  4. using modules only when available
    By Phil Schaechter in forum PERL Beginners
    Replies: 5
    Last Post: October 27th, 10:42 PM
  5. Modules for XS.
    By Java Guy in forum PERL Beginners
    Replies: 0
    Last Post: October 20th, 02:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139