Hi, I have this small bank program and I am using tie and a hash. Basically I am bulding a multi-value values for eah single key. In my LIST_ALL and LIST_ACCOUNT subs, the values of the has don't print. Am I doing something wrong? Also do I need to use an anonymous hash in CREATE_ACCOUNT sub, can I just use a regular hash?
Thanks ##### use DB_File; use strict; print <<EOF; ########################## (C) Create an account (L) List an account (A) List all account (P) Make a deposit (D) Delete an account (Q) Quit ########################## EOF my ($fname,$lname,$depot); my %USER; my $opt = <STDIN>; chomp($opt); $opt = uc($opt); while ( $opt ne 'Q' ) { if ( $opt eq 'C' ) { &CREATE_ACCOUNT; } elsif ( $opt eq 'L' ) { &LIST_ACCOUNT; } elsif ( $opt eq 'A' ) { &LIST_ALL; } elsif ( $opt eq 'D' ) { &DELETE_ACCOUNT;} elsif ( $opt eq 'P' ) { &DEPOSIT; } elsif ( $opt eq 'Q' ) { exit;} print <<EOF; ########################## (C) Create an account (L) List an account (A) List all account (P) Make a deposit (D) Delete an account (Q) Quit ########################## EOF $opt = <STDIN>; chomp($opt); $opt = uc($opt); } sub CREATE_ACCOUNT { print "FIRST NAME: \n"; $fname = <STDIN>; chomp($fname); print "LAST NAME: \n"; $lname = <STDIN>; chomp($lname); print "INITIAL DEPOSIT: \n"; $depot = <STDIN>; chomp($depot); my $count = &COUNTER; tie(%USER, "DB_File","USERDBM2") || die "Cannot open DBM\n"; my @all = ("$fname","$lname","$depot"); $USER{"$count"} = [ @all ]; untie(%USER); } sub COUNTER { my $count; open (FP,"counter.txt"); my $num = <FP>; $num++; close(FP); open (FP,">counter.txt"); print FP "$num"; close(FP); return "$num"; } sub LIST_ACCOUNT { print "Enter ID :\n"; my $id = <STDIN>; chomp($id); tie(%USER, "DB_File","USERDBM2") || die "Cannot open DBM\n";; if ( $USER{$id} ) { foreach (keys %USER) { if ( m!$id! ) { print "@{$USER{$_}}\n"; } } } untie(%USER); } sub LIST_ALL { no strict; tie(%USER, "DB_File","USERDBM2") || die "Cannot open DBM\n";; foreach my $id ( keys %USER) { print "$id ---> @{ $USER{$id} }"; print "\n--------------\n"; } untie(%USER); } __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs