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

In reply to Re^2: Optional Arguments..? by Watergun
in thread Optional Arguments..? by Watergun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.