Hello monks,

I frequently replicate others' posts so as to help if I can, learn more of a gigantic language, and have new scripts that will improve my own capabilities. So it is that chungley2000 rolled in with a question that morphed into about how to get values from Config. I've been playing with the values for a couple days now, and I wrote a script to see what output resulted from the 4 method function calls that this module exports. I've commented out failed attempts to herd these values into lexical variables.

#!/usr/bin/perl -w use 5.011; use Config qw(myconfig config_sh config_vars config_re); use Data::Dumper; say myconfig(); say "---------------"; say config_sh(); say "---------------"; say config_vars(); say "---------------"; my $ref_Env = \%ENV; say Dumper $ref_Env; my $version = config_re("version"); say "version is $version"; # my $archname = $Config{'archname'}; #produces error: %Config unknown say "---------------"; #my $ref_Config = \%CONFIG; #say Dumper $ref_Config;

Abridged output, where I've commented on values with a double hashmark:

Summary of my perl5 (revision 5 version 26 subversion 1) configuratio +n: Platform: osname=linux osvers=4.9.0 archname=x86_64-linux-gnu-thread-multi --------------- Author='' CONFIG='true' ## big snip from say myconfig(); zcat='' zip='zip' --------------- ##nothing for say config_sh(); --------------- $VAR1 = { 'TEXTDOMAIN' => 'im-config', 'SSH_AUTH_SOCK' => '/run/user/1000/keyring/ssh', 'IM_CONFIG_PHASE' => '2', 'PERL5LIB' => '/home/bob/perl5/lib/perl5', ## snip in ENV data 'LESSCLOSE' => '/usr/bin/lesspipe %s %s' }; version is 1 ##config_re("version"); ---------------

My experience with the large family of Config modules has been with Config::Tiny, where I have imported such values from an .ini file. Now I would like to import the values from the myconfig() method into a hash.

If I had to get values quick and dirty, I would create a temp file with Path::Tiny, then read it with Config::Tiny. But when you have the darn thing in memory already, it seems like a significant work-around, in particular, when you are only going to delete the file for being a security risk. I don't want these data to be persistent beyond the first few lines of a perl script. Other modules from the Config namespace seem promising, but, for example CONFIG::Hash seems like it might be the thing I'm looking for, but not quite. There are at least 12 screens of matches for Config in cpan.

I could also use bash to pipe these values, but do I really need a shell? It seems like there could be a perl-only solution to this, which is more portable. My question then is how to to herd the = joined and newline separated values from

config_vars()

into a hash.

Thank you for your comment,


In reply to how to get Config values into a hash by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.