basic use of modules

B

BH

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
 
B

Ben Morrow

Quoth BH said:
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
 
B

BH

Thanks a lot.

Quoth BH <[email protected]>:








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.


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

Ben
 
T

Ted Zlatanov

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top