Hello Monks,
I have written a script that wraps Java Keytool in perl to list the certificates in a keystore. I am using a foreach loop through the output from Keytool and pull the name of the certificate and the expiration date. I want to put the values into an array of hashes but I cannot quite understand how to get that to happen. What I am trying to get to is something like this...
@AoH = (
{
$certName => $validTo,
$certName => $validTo,
}
);
I declare a global array of hashes at the beginning of the script with:
our @foundCertificates();
I have the following subroutine setup to parse through the output from the keytool to pull the certificate names and the date they are valid to:
sub parseResponse {
my $out = shift;
my $certname;
my $validTo;
my $retMonth;
foreach my $line (split ("\n", $out)) {
if ($line =~ m/^(Alias\sname:\s)(.+)/) {
$certname = $2;
#print "$certname\n";
} elsif ($line =~ m/^(Valid\sfrom:\s\w+\s)(\w+)\s(\d\d)\s(\d\d:\
+d\d:\d\d)\s\w+\s(\d+)\s(until:)\s\w+\s(\w+)\s(\d\d)\s(\d\d):(\d\d):(\
+d\d)\s\w+\s(\d\d\d\d)/) {
$retMonth = &convertMonth($7);
$validTo = timegm($11,$10,$9,$8,$retMonth,$12);
#print "$validTo\n";
}
}
#print "$certname - $validTo\n";
}
I know that my regular expressions work as the script captures the three certificates in my keystore, but what I cannot figure out to do is how to push the $certname and the $validTo in the array as a pair. I am not sure what other information I can provide, but any help is greatly appreciated.
Thanks,
Scott
-
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.