in reply to Re: redacting from config hash
in thread redacting from config hash
I'm very grateful for 2 excellent responses. I've coded toward both haukex's and soonix's suggestions, and I haven't completely disentangled ideas that are still crowding out the good ones here. I think I can lay out what I've done, state a better specification, and outline the things that cause trouble.
I looked also at config1.pm and realized that my claim that I only had sensitive values in one file per workspace was false. My new specification for the copy to the temp directory is that any file that matches "config", then a number, a dot, and a "pm" shall not be copied. Meanwhile, I have a created a template file, config3.tmpl, that is of the form it needs to be less the definition of the hash, which is to be templated in. I don't see why Text::Template wouldn't be fine. The longer arc of my question is how to both to populate and depopulate such hashes. What makes it very difficult is that we seem to be acting on perl syntax itself.
If we look haukex's output, the hash begins
$CONFIG = { my_github => {
, yet if we're to imitate the syntax in my source it begins:
our %config = ( my_sftp => {
I'm more than a little confused about what seem to be competing definitions of a hash.
$ cat config3.tmpl package config3; use Exporter qw(import); our @EXPORT = qw(%config); {$config_hash} 1; ---------- $ cat util2.pm package utils2; require Exporter; use utils1; our @ISA = qw(Exporter); our @EXPORT = qw( redact make_ini); sub redact{ use strict; use warnings; use 5.010; use Path::Tiny; my $file = shift; #use $file; resulted in error use config2; my $sub_hash = "my_github"; my $email = $config{$sub_hash}->{'email'}; my $password = $config{$sub_hash}->{'password'}; my $tempdir = Path::Tiny->tempdir('backup_XXXXXX'); say "temp dir is $tempdir"; my $scratch_file = $tempdir->child('batch_01', '1.manifest.txt')->touc +hpath; say "scratch_file is $scratch_file"; my $parent = $scratch_file->parent; say "parent is $parent"; chdir $tempdir unless $tempdir->subsumes(Path::Tiny->cwd); system("pwd"); use Data::Dumper; print Dumper \%config; my $b = "dummy"; return $b; } sub make_ini{ use strict; use warnings; use 5.010; use Path::Tiny; my $file = shift; use config2; use Config::Tiny; use Data::Dumper; my $path = shift; say "path is $path"; say "is the stuff here?"; print Dumper \%config; $config->write( $path, 'utf8' ); #this line draws error chdir "/home/bob/Documents"; system("cat *.ini"); my $b = "dummy"; return $b; } 1;
What I tried to do was extend what I have now to create a Config::Tiny ini file. I think the install went well, and judging by how quickly it went, it truly seems tiny:
All tests successful. Files=5, Tests=49, 3 wallclock secs ( 0.06 usr 0.01 sys + 0.45 cusr + 0.10 csys = 0.62 CPU) Result: PASS RSAVAGE/Config-Tiny-2.23.tgz /usr/bin/make test -- OK Running make install Manifying 1 pod document Installing /usr/local/share/perl/5.26.1/Config/Tiny.pm Installing /usr/local/man/man3/Config::Tiny.3pm Appending installation info to /usr/local/lib/x86_64-linux-gnu/perl/5. +26.1/perllocal.pod RSAVAGE/Config-Tiny-2.23.tgz /usr/bin/make install -- OK cpan[2]> q Terminal does not support GetHistory. Lockfile removed. $ man Config::Tiny $ ./1.redact.pl Variable "$config" is not imported at template_stuff/utils2.pm line 61 +. Global symbol "$config" requires explicit package name (did you forget + to declare "my $config"?) at template_stuff/utils2.pm line 61. Compilation failed in require at ./1.redact.pl line 6. BEGIN failed--compilation aborted at ./1.redact.pl line 6.
$ cat config2.pm package config2; use Exporter qw(import); our @EXPORT = qw(%config); our %config = ( my_sftp => { domain => '', username => '', password => '', }, my_github => { email => '', password => '', }, ); 1; $
I don't seem to be sharing is the "our" on the definition of "our %config". Why is my syntax on the config hash clashing with that provided by man Config::Tiny and haukex?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: redacting from config hash
by haukex (Archbishop) on Aug 01, 2018 at 09:16 UTC | |
by Aldebaran (Curate) on Aug 02, 2018 at 23:09 UTC | |
by hippo (Archbishop) on Aug 03, 2018 at 08:34 UTC | |
by Aldebaran (Curate) on Aug 06, 2018 at 21:39 UTC | |
by haukex (Archbishop) on Aug 03, 2018 at 08:36 UTC | |
by Aldebaran (Curate) on Aug 06, 2018 at 21:28 UTC | |
|
Re^4: redacting from config hash
by soonix (Chancellor) on Aug 01, 2018 at 12:53 UTC | |
by Aldebaran (Curate) on Aug 02, 2018 at 07:02 UTC |