Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Here's what I finally came up with.

This time around thanks go to Fastolfe and chromatic for all but drawing me a picture of how to use Tie::IxHash, to tilly for pointing me to Data::Dumper recently on an unrelated question in the Chatbox, to ChOas for Yet Another (simpler) Way To Do It, and to AgentM even though I didnt' use his idea.

/msg's or replies welcome if any fine Monks spot something I'm doing in a dumb or dangerous manner.
    cheers,
    Don
    striving for Perl Adept

1 #!/usr/bin/perl -w 2 # getpass.pl 3 4 5 use strict; 6 use Term::ReadKey; 7 use Tie::IxHash; 8 #use Data::Dumper; # Only for testing. 9 #use vars qw(); # Don't need if all vars declared with "my". 10 11 12 # Tied hash of on-screen prompts for old/new passwords 13 tie my %prompts, "Tie::IxHash" 14 %prompts = ( 15 'Enter old password:' => 'oldpass', 16 'Enter old enable password:' => 'oldenable', 17 'Enter new password:' => 'newpass', 18 'Confirm new password:' => 'passconf', 19 'Enter new enable password:' => 'newenable', 20 'Confirm new enable password:' => 'enableconf', 21 ); 22 23 24 # Walk through each prompt to populate a new tied Hash of passwords +: 25 print "Prompting for passwords (no screen echo)\n\n" 26 tie my %passwds, "Tie::IxHash" 27 for my $prompt (keys %prompts) { 28 print " $prompt " 29 ReadMode('noecho'); # don't echo to screen. 30 chomp(my $input = <STDIN>); 31 $passwds{$prompts{$prompt}} = $input; 32 ReadMode(0); # re-activate screen echo. 33 print "\n" 34 } 35 print "\n" 36 37 38 # Create named scalars for %passwds values: 39 # Probably a kludge-free way to do this, 40 # but I haven't encountered it yet. 41 my $oldpass = ($passwds{"oldpass"}); 42 my $oldenable = ($passwds{"oldenable"}); 43 my $newpass = ($passwds{"newpass"}); 44 my $passconf = ($passwds{"passconf"}); 45 my $newenable = ($passwds{"newenable"}); 46 my $enableconf = ($passwds{"enableconf"}); 47 48 49 ## Following stuff only for testing, 50 ## since they display what's so carefully hidden 51 ## using Term::Readky's ReadMode('noecho'). 52 53 54 # print values via named scalars: 55 #print $oldpass, "\n" 56 #print $oldenable, "\n" 57 #print $newpass, "\n" 58 #print $passconf, "\n" 59 #print $newenable, "\n" 60 #print $enableconf, "\n" 61 62 63 # print values individually: 64 #print $passwds{"oldpass"}, "\n" 65 #print $passwds{"oldenable"}, "\n" 66 #print $passwds{"newpass"}, "\n" 67 #print $passwds{"passconf"}, "\n" 68 #print $passwds{"newenable"}, "\n" 69 #print $passwds{"enableconf"}, "\n" 70 #print "\n" 71 72 73 # print all key/value pairs for both hashes: 74 #print Dumper(%prompts), "\n" 75 #print Dumper(%passwds), "\n" 76 77 78 # print all 6 key/value pairs: 79 #while ((my $key, my $value) = each %passwds) { 80 # print " $key => $value\n" 81 #} 82 #print "\n" 83 84 85 # print all 6 keys: 86 #for my $passwd (keys %passwds) { 87 # print " $passwd \n" 88 #} 89 #print "\n" 90 91 92 # print all 6 values: 93 #for my $passwd (values %passwds) { 94 # print " $passwd \n" 95 #} 96 #print "\n"

In reply to (code) RE: Scalars as hash keys? (solution!) by ybiC
in thread Scalars as hash keys? by ybiC

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2015-07-28 02:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (251 votes), past polls