Home > Archive > PERL Miscellaneous > February 2008 > basic use of modules
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
basic use of modules
|
|
|
| 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
| |
| Ben Morrow 2008-02-26, 10:09 pm |
|
Quoth BH <Benson.Hoi@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
| |
|
| Thanks a lot.
On Feb 26, 3:47=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth BH <Benson....@googlemail.com>:
>
>
>
>
>
>
>
>
> 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
| |
| Ted Zlatanov 2008-02-26, 10:09 pm |
| On Tue, 26 Feb 2008 15:47:38 +0000 Ben Morrow <ben@morrow.me.uk> wrote:
BM> Quoth BH <Benson.Hoi@googlemail.com>:[color=darkred]
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
|
|
|
|
|