basic use of modules

Discussion in 'Perl Misc' started by BH, Feb 26, 2008.

  1. BH

    BH Guest

    Hi,

    I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
    got a big list of variables using saying which header is in which
    column. I want to store these in another file.

    How do I do this?

    e.g.
    require "constants.pl";

    use spreadsheet_constrants;

    Which one is better practice?

    I tried the 2nd option, however I got the error "variable xxx is not
    imported". Why? What does it mean? What's the usual cause?

    Regards,

    BH
    BH, Feb 26, 2008
    #1
    1. Advertising

  2. BH

    Ben Morrow Guest

    Quoth BH <>:
    >
    > I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
    > got a big list of variables using saying which header is in which
    > column. I want to store these in another file.
    >
    > How do I do this?
    >
    > e.g.
    > require "constants.pl";
    >
    > use spreadsheet_constrants;
    >
    > Which one is better practice?


    The second. However, you may find it more awkward if you really want a
    big list of variables to import. A better option would be to put these
    constants into a single hash, instead, and then import that; a third
    would be to use the 'constant' module to define proper named constants.

    > I tried the 2nd option, however I got the error "variable xxx is not
    > imported". Why? What does it mean? What's the usual cause?


    You need to read perldoc perlmod, and then probably perldoc Exporter.
    Post again if you don't understand those two documents.

    Ben
    Ben Morrow, Feb 26, 2008
    #2
    1. Advertising

  3. BH

    BH Guest

    Thanks a lot.

    On Feb 26, 3:47 pm, Ben Morrow <> wrote:
    > Quoth BH <>:
    >
    >
    >
    > > I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
    > > got a big list of variables using saying which header is in which
    > > column. I want to store these in another file.

    >
    > > How do I do this?

    >
    > > e.g.
    > > require "constants.pl";

    >
    > > use spreadsheet_constrants;

    >
    > > Which one is better practice?

    >
    > The second. However, you may find it more awkward if you really want a
    > big list of variables to import. A better option would be to put these
    > constants into a single hash, instead, and then import that; a third
    > would be to use the 'constant' module to define proper named constants.
    >
    > > I tried the 2nd option, however I got the error "variable xxx is not
    > > imported". Why? What does it mean? What's the usual cause?

    >
    > You need to read perldoc perlmod, and then probably perldoc Exporter.
    > Post again if you don't understand those two documents.
    >
    > Ben
    BH, Feb 26, 2008
    #3
  4. BH

    Ted Zlatanov Guest

    On Tue, 26 Feb 2008 15:47:38 +0000 Ben Morrow <> wrote:

    BM> Quoth BH <>:
    >>
    >> I am reading from a spreadsheet using Spreadsheet::BasicRead, I have
    >> got a big list of variables using saying which header is in which
    >> column. I want to store these in another file.
    >>
    >> How do I do this?
    >>
    >> e.g.
    >> require "constants.pl";
    >>
    >> use spreadsheet_constrants;
    >>
    >> Which one is better practice?


    BM> The second. However, you may find it more awkward if you really want a
    BM> big list of variables to import. A better option would be to put these
    BM> constants into a single hash, instead, and then import that; a third
    BM> would be to use the 'constant' module to define proper named constants.

    The OP could put all that data in a file (YAML, XML, CSV, etc). It
    would be faster on load too, if the list is big. I can't tell the OP
    what format to use since I don't know how the header name and the column
    name are defined, but probably even something as simple as

    1 name
    2 address
    3 zip code

    in a plain text file would work, to be processed with

    split " ", $line, 2;

    I've said it before and I'll say it again, storing pure data in code is
    a bad idea, especially if the data structure is simple.

    Ted
    Ted Zlatanov, Feb 26, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Remy Cool
    Replies:
    1
    Views:
    429
    Remy Cool
    Aug 27, 2003
  2. Engineer
    Replies:
    6
    Views:
    611
    Jeremy Bowers
    May 1, 2005
  3. Replies:
    0
    Views:
    428
  4. Negroup
    Replies:
    2
    Views:
    1,059
    Kay Schluehr
    Jun 10, 2005
  5. Merrilee Larson

    Do I *have* to use 'OOP' to use modules?

    Merrilee Larson, Nov 17, 2006, in forum: Perl Misc
    Replies:
    41
    Views:
    367
    Arved Sandstrom
    Nov 25, 2006
Loading...

Share This Page