Updating the hash across the files

Hi all,=20

I have a .pm file which has a hash defined in the pm file along with the bl=
essed class.=20

For exp:=20

package A::Colour;=20

It is a hash that is bless with the class.=20
our %color_of =3D (=20
    "apple"  =3D> "red",=20
    "orange" =3D> "orange",=20
    "grape"  =3D> "purple",=20


I want to modify this hash(A.pm) from a A.pl file which receives command li=
ne arguments.=20

A.pl [command line arg1] [command line arg2] [command line arg3]=20

So I did the following:=20

A. pl=20

my $a =3D $ARGV[0];=20
my $b =3D $ARGV[1];=20

require A::Colour;=20
my $obj =3D A::Colour->new();=20

$obj->{apple} =3D $a;=20
$obj->{orange} =3D $b;=20

print "$obj->{apple}"; # This doesnt print the updated values. I would expe=
ct the command line arguments value should have been updated in the hash. B=
ut it is not the case.=20

$obj->{apple} still prints "red". This is probably the scope of the object =
is lost between the files.=20

One way to fix this issue I think is to create the set/get function in A.pm=
 and import the functions to the A.pl file. But that will increase the code=
 size in the A.pm as for each variable in the hash you need public methods(=
set/get). Is there any efficient and cleaner way?=20

Can anyone help me in this regard?=20


8/20/2016 3:25:08 AM
comp.lang.perl.modules 4194 articles. 0 followers. jerrykrinock (6) is leader. Post Follow

0 Replies

Similar Articles

[PageSpeed] 17