Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

module reference is used in a confusing way

by gwhite (Friar)
on Nov 07, 2008 at 19:01 UTC ( #722271=perlquestion: print w/ replies, xml ) Need Help??
gwhite has asked for the wisdom of the Perl Monks concerning the following question:

Going through some code someone else wrote and found this and I don't understand it. Can someone shed some light?

#this creates a new $config thing my $config = new ConfigReader::Simple($config_file); #this checks for a true in one of the elements of the $config if ($config->adv_conf){ ... } #this creates an array out of a list of words my @batch_list = split /\s+/, $config->batch_list; #the next line puts a reference to the array into the $config #but why the $$ and no -> $$config{batch_list} = \@batch_list; #could it be done just as easily with this $config->set(batch_list, \@batch_list); #I am thinking probably not since the doc says: #set( DIRECTIVE, VALUE ) #Sets the value for DIRECTIVE to VALUE. The DIRECTIVE need not already + exist. This overwrites previous values. #The VALUE must be a simple scalar. It cannot be a reference. If the V +ALUE is a reference, the function prints a warning and returns false.

and what are the proper ways to access that $config element?
my @list = @{$$config{batch_list}};
my @list = @{$config->batch_list};


Comment on module reference is used in a confusing way
Download Code
Replies are listed 'Best First'.
Re: module reference is used in a confusing way
by kennethk (Abbot) on Nov 07, 2008 at 19:41 UTC
    $$config{batch_list} = \@batch_list

    This stores a reference to the @batch_list array in the 'batch_list' element of an anonymous hash. The reference to the anonymous hash is stored in $config. If you want to access the stored array, it can be read as

    my @list = @{$$config{batch_list}}


    my @list = @{$config->{batch_list}}

    as well, I'm sure, as a half dozen other ways.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://722271]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2015-11-28 03:11 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls