Hi Dave!
Firstly I wanna say I almost burst into happiness when you explained this.. "defined" to me. It's the one thing that my lecturer told us to google for, to implement in our codes but I just couldn't find a simple explanation to use this. Thanks a lot. Right now after using defined, my code looks like this
#!/usr/bin/perl -w use strict; use warnings; use ST2614 1.0; #subroutine guide provides user a simple documentation on how to use t +he password manager sub guide { my $pwdmgr = shift; print "usage: $pwdmgr L key [site_pattern]\n"; print "-"x5, " takes the encoding key and optional site_pattern to + retrieve all saved entries that match.\n If no site_pattern, retrieve all s +aved entries\n\n"; print "usage: $pwdmgr U key site_name login_id password [URL]\n"; print "-"x5, " Using the encoding key, add new or update existing +entry.\n Complete set of entry info required: Site name, login id, password, URL(Optional)\ +n\n"; print "usage: $pwdmgr D key site_name\n"; print "-"x5, " Takes in encoding key and site_name to delete entry +; will only work if encoding key matches and entry found matching with site_name.\n"; exit; } #an if-elsif loop to check which option user has selected if ($ARGV[0] eq "L") { sub listFunct ($;$) { open(FILEHANDLE, "passmgr.dat") or die ("The file cannot be op +ened!"); my $decode = ST2614::decode(FILEHANDLE, $ARGV[1]); if ( defined $ARGV[2] ) { for $decode (keys =~ m/$ARGV[2]/) { print "$decode: @{ m/$ARGV[2]/ {$decode} }\n"; + } } else { for $decode () { print } } } } elsif ($ARGV[0] eq "U") { #declare the individual variables that are to be stored my $sitename = $ARGV[2]; #sitename will be the key in the hash of +array my $loginid = $ARGV[3]; my $password = $ARGV[4]; my $url = $ARGV[5]; #declare a hash of array to prepare storage of all variables to be + encoded together my HoA {$sitename} = ["$loginid", "$password", "$url"];; open(FILEHANDLE, ">>passmgr.dat") or die("The file cannot be opene +d!"); my $encode = ST2614::encode(HoA, $ARGV[1]); print FILEHANDLE "$encode"; close FILEHANDLE; print "Data successfully encoded. Please remember your key.\n Your + key is $ARGV[1]."; } elsif ($ARGV[0] eq "D") { } else { guide($0); }
What I want to achieve is to be able to print all password and related data by searching for the sitename, so for example searching for 'a' might give me yahoo and facebook, and list the passwords accordingly. Is my following code correct?
Also, I would like to be able to print all hashes of arrays in my decoded file, how do I do that?
With thanks JunmingIn reply to Re^2: Optional Arguments..?
by Watergun
in thread Optional Arguments..?
by Watergun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |