Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Reference to a sub return / Config::General

by jeffa (Bishop)
on Jan 22, 2004 at 22:06 UTC ( #323335=note: print w/replies, xml ) Need Help??


in reply to Reference to a sub return / Config::General

Config::General was designed to take a text file, parse it, and return the results in a hash. You could patch the code to return a hash reference instead, but if your config file is gigantic in the first place, then maybe you are designing something wrong. Most config files i work with never make into the megabyte range (or even over 100K for that matter).

Regardless of whether you use:

my $config = { Config::General->new('my.conf')->getall() };
or
my %config = Config::General->new('my.conf')->getall(); my $config = \%config;
some copying will need to be performed. Don't worry about size unless you have to, and it sounds like you really don't.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Re: Reference to a sub return / Config::General
by Oberon (Monk) on Jan 22, 2004 at 22:33 UTC
    > Don't worry about size unless you have to, and it sounds like you really don't.

    I know, I know: don't microoptimize. But it's the principle dammit! <s>

    No, I shan't worry about it. But I thought maybe there was some way around it that would teach me something new. <he said wistfully ...>

      But I thought maybe there was some way around it

      If the subroutine returns a list instead of a hashref, there's not much you can do about it.

      Just for a little bit more explanation: when you say return %hash, the hash gets flattened into a plain ol' list. When you subsequently say my %hash = foo(), that shoehorns the list into a new hash. Again, there's nothing you can do about this without modifying the subroutine's return statement.

        > when you say return %hash, the hash gets flattened into a plain ol' list. When you subsequently say my %hash = foo(), that shoehorns the list into a new hash.

        Ah, I hadn't thought of it that way. So I'm not only running into the difference between a value and a variable, but also the difference between a list and an array.

        Although, come to think of it, those are basically analogous ...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2019-11-13 08:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (70 votes). Check out past polls.

    Notices?