encapsulate static data

Hello:
I have some static data I want to wrap in a Data.pm, what is the best
way of doing this.

package data;
use strict;
use warnings;

my $data=1;
1;

I tried
use data;
print $data; but it doesn't work, also I tried print data::$data and
still doesn't work.

Thanks for helping!
Jim


--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Jim Green [ Do, 10 Februar 2011 02:57 ] [ ID #2054942 ]

Re: encapsulate static data

On 11-02-09 08:57 PM, Jim Green wrote:
> Hello:
> I have some static data I want to wrap in a Data.pm, what is the best
> way of doing this.
>
> package data;

package Data; # unless it's a pragmatic, it's capitalized

> use strict;
> use warnings;
>
> my $data=1;

This is lexically scoped to the file. Use one of:

$::data = 1; # no my in front

or

use base qw( Exporter );
our [at] EXPORT = qw( $data );


> 1;
>
> I tried
> use data;
> print $data; but it doesn't work, also I tried print data::$data and
> still doesn't work.

Try: $Data::data instead.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Do, 10 Februar 2011 14:52 ] [ ID #2054955 ]
Perl » gmane.comp.lang.perl.beginners » encapsulate static data

Vorheriges Thema: about return
Nächstes Thema: Randomizing a 24hr time period