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
Junming
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.