Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Optional Arguments..?

by poj (Priest)
on Jun 03, 2012 at 13:12 UTC ( #974144=note: print w/ replies, xml ) Need Help??


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

OK, looks like arguments are text strings, not a filehandle or a hash ref. Can you show some lines of data from the passmgr.dat file.
poj


Comment on Re^3: Optional Arguments..?
Download Code
Re^4: Optional Arguments..?
by Watergun (Novice) on Jun 03, 2012 at 13:24 UTC

    I don't really know how to copy and paste output from my terminal, but basically it goes like this (not real output)

    1,92,54,12,32,53,23,54,11,53,68,77

    However I have no error with encoding. I just can't.. figure out how to code it when it involved decoding data (an additional step from basic printing of my hash array)
      You can't store all the data you need like this ;
      # 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 opened!"); my $encode = ST2614::encode($HoA, $ARGV[1]); print FILEHANDLE "$encode"; close FILEHANDLE;
      Consider using a tab delimiter record format like this ;
      sitename1 loginid1 encoded_password1 url1 sitename2 loginid2 encoded_password2 url2 sitename3 loginid3 encoded_password3 url3
      Then you can build a HoA from the file like this
      my $key = $ARGV[1] || 'secretkey'; my %HoA=(); open IN, '<','passmgr.dat' or die ("The file cannot be opened!"); while (<IN>){ chomp; my ($sitename,$id,$enc_password,$url) = split "\t",$_; my $password = ST2614::decode($enc_password, $key); $HoA{$sitename} = [$id,$password,$url]; # print "$sitename $id $password $url\n"; }
      and save it to the file like this
      open OUT, '>','passmgr.dat' or die ("The file cannot be opened!"); for my $sitename (sort keys %HoA){ my $id = $HoA{$sitename}[0]; my $enc_password = ST2614::encode($HoA{$sitename}[1], $key); my $url = $HoA{$sitename}[2]; print OUT join "\t",$sitename,$id,$enc_password,$url,"\n"; }
      poj

        Thanks for the reply!

        But could you kindly explain what the code you provided does, and how does it work? As I'm very new to Perl, I don't understand some of the code yet.

        If I am not wrong, you are only encoding the password, but my aim is to encode everything that the user entered.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://974144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-10-02 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (51 votes), past polls