in reply to Simple Hash Question

IMO your subroutine seems to be fine
however, you may have problems in the place where you are calling this subroutine
at all these tough times, perl -d is your helper; use it; see perldebug
BTW your post title, 'simple hash question' seems to be irrelevant to the post!.

UPDATE
good that you know you can use hashes, why you have not tried it?.
see here about hashes
for your case you can use some thing like below

my %flag; .. $flag{'user'} = $user; .. $flag{'uid'} = $uid; ... ... return %flag; at the calling place use my %userflags = buildCommand(..) then access the values like $userflags{'user'} or use references return \%flag; at the calling place use my $userflags = buildCommand(..) then access the values like $userflags->{'user'}
see perlref for more details on references.
learning perl is a good place to start.

Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.

Replies are listed 'Best First'.
Re^2: Simple Hash Question
by walkingthecow (Friar) on May 22, 2009 at 15:35 UTC
    Hm, so I am still at a roadblock here. I guess I do not understand how I would do it... Here is what I have, but as you can see I still have to evaluate what comes in... The problem is, this: "my ($user,$uid,$group,$home,$create,$shell)=@_;" is not doing anything at all. It is never evaluated, and I am unsure a nice clean way of doing that.
    sub buildCommand { my ($user,$uid,$group,$home,$create,$shell)=@_; my %flag; while (1) { print qq { 1. User: $user 2. UID: $uid 3. Group: $group 4. Home Dir: $home 5. Comment: $comment 6. Shell: $shell D. Done }; print "Please Choose An Option From Above: " chomp(my $ans=<STDIN>); if ($ans == 1) { $flag{'user'} = getInput("Enter Username: "); } elsif ($ans == 2) { $flag{'uid'} = getInput("Enter UID: "); } elsif ($ans == 3) { $flag{'group'} = getInput("Enter Group: "); } elsif ($ans == 4) { $flag{'home'} = getInput("Enter Home: "); } elsif ($ans == 5) { $flag{'comment'} = getInput("Enter Comment: "); } elsif ($ans == 6) { $flag{'shell'} = getInput("Enter Shell: "); } elsif ($ans =~ /d/i && defined($user)) { last; } else { print "INVALID OPTION!\n"; } } while (($key, $value) = each(%flag)){ $flag .= "-$key $value "; } return(%flag); }