• Updating the hash across the files

    From bubunia2000ster@gmail.com@21:1/5 to All on Fri Aug 19 20:25:08 2016
    Hi all,

    I have a .pm file which has a hash defined in the pm file along with the blessed class.

    For exp:

    A.pm
    ====
    package A::Colour;

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

    1;

    I want to modify this hash(A.pm) from a A.pl file which receives command line arguments.

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

    So I did the following:

    A. pl
    ====

    my $a = $ARGV[0];
    my $b = $ARGV[1];

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

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

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

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

    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?

    Can anyone help me in this regard?

    Regards
    Pradeep

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)