I would use Exporter and create accessors for the data rather than accessing the data directly.

package Foo; use warnings; use strict; use base 'Exporter'; our @EXPORT_OK = qw( some_data some_more_data fribble ); sub some_data { 'foo' } sub some_more_data { 'bar' } my %gnarfles = ( this => 1, that => 'one' ); sub fribble { my $key = shift; if (exists $gnarfles{$key}) { return $gnarfles{$key}; } else { die "No such value ($key)"; } } 1;

And in your actual program:

use Foo qw'fribble some_data'; my $result = fribble($key);

By properly encapsulating your data in accessors, you make it much easier to extend and make it easier to validate. Also, by adding it to @EXPORT_OK instead of @EXPORT, you ensure that people only import the functions that they need and, more importantly, it is very easy to track down where the function came from.

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: storing data in a package/module by Ovid
in thread storing data in a package/module by nmerriweather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.