Hi Monks, as I continue my headlong assault at friarhood, I'm trying to write up a meditation about Path::Tiny, which I'm re-writing my previous scripts with and writing new code with. The task before me is to bundle up my template and get in online, without publishing any sensitive data. I have no perfect divorce of content and data, but I have confined the stuff I don't want all over the net to one hash in config2.pm . The first thing I intend to do is to make a copy of config2.pm in a temporary directory without the values in the hash.

Can you "use" a lexical variable? What follow are the driver script, output and then utils2.pm, where redact() is to reside.

#!/usr/bin/perl -w use strict; use 5.010; use lib "template_stuff"; use utils1; use utils2; use utf8; use open qw/:std :utf8/; use Path::Tiny; my $current = Path::Tiny->cwd; say "current is $current"; my $return = redact("config2"); __END__ current is /home/bob/1.scripts/pages/1.qy temp dir is /tmp/backup_DEtSio scratch_file is /tmp/backup_DEtSio/batch_01/1.manifest.txt parent is /tmp/backup_DEtSio/batch_01 /tmp/backup_DEtSio $VAR1 = { 'my_sftp' => { 'username' => '', 'password' => '', 'domain' => '' }, 'my_github' => { 'password' => '', 'email' => '' } };
package utils2; require Exporter; use utils1; our @ISA = qw(Exporter); our @EXPORT = qw( redact); 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; } 1;

Obviously, I edited out the values with the delete key, and I'd like them to simply show "redacted". There are some bad ideas chasing some good ones here. Eventually, I'd like to have an entire directory tree populated in the temp dir and then compressed by some means to a single file. If I'm going to port to windows, what is a good choice for compression software? Thanks for your comment.


In reply to redacting from config 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.