Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > basic use of modules

Reply
Thread Tools

basic use of modules

 
 
BH
Guest
Posts: n/a
 
      02-26-2008
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
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      02-26-2008

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

 
Reply With Quote
 
 
 
 
BH
Guest
Posts: n/a
 
      02-26-2008
Thanks a lot.

On Feb 26, 3:47*pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth BH <Benson....@googlemail.com>:
>
>
>
> > 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


 
Reply With Quote
 
Ted Zlatanov
Guest
Posts: n/a
 
      02-26-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing v reloading modules modules Peter Peyman Puk Python 0 03-19-2010 05:09 PM
Disabling modules using Modules/Setup Ben Weintraub Python 0 09-09-2006 12:04 AM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02:25 PM



Advertisments
 



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