in reply to Re: Scalars as hash keys?
in thread Scalars as hash keys?

I think he wanted to tie %prompts so that his loop would ask the prompts in the order he defined them above. A normal hash would have asked them all out-of-order...

Replies are listed 'Best First'.
RE: (3) Scalars as hash keys? (tie %prompts)
by ybiC (Prior) on Oct 27, 2000 at 00:50 UTC
    Now it's Fastolfe who's reading my mind {g}.   Just encountered "asked them all out-of-order".

    So... 2 questions:
    A - how do I tie my %prompts = (blah blah); ?
    II - does $tied_hash{$prompts{$prompt}} = $input still need to be tied?

    Here's what I've got so far:

    1 #!/usr/bin/perl -w 2 # getpass.pl 3 4 use strict; 5 use Term::ReadKey; 6 use Tie::IxHash; 7 8 # Hash of on-screen prompts for old/new passwords 9 my %prompts = ( 10 'Enter old password:' => 'oldpass', 11 'Enter old enable password:' => 'oldenable', 12 'Enter new password:' => 'newpass', 13 'Confirm new password:' => 'newpassconf', 14 'Enter new enable password:' => 'newenable', 15 'Confirm new enable password:' => 'newenableconf', 16 ); 17 18 # Walk through each on-screen prompt to populate new Hash of passwo +rds 19 print "Prompting for passwords (*won't* appear on-screen)\n\n" 20 my %passwds; 21 for my $prompt (keys %prompts) { 22 print " $prompt " 23 ReadMode('noecho'); 24 chomp(my $input = <STDIN>); 25 $passwds{$prompts{$prompt}} = $input; 26 ReadMode(0); 27 print "\n" 28 }

    In case I haven't already mentioned it, y'all's help is truly appreciated.   Double, no, make that triple++.
        cheers,
        Don
        striving for Perl Adept