Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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};

g_White

Comment on module reference is used in a confusing way
Download Code
Re: module reference is used in a confusing way
by kennethk (Monsignor) 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}}

    or

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

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (185 votes), past polls