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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.