Here is a modified version of your code that builds a hash allowing lookup either by user or smartcard id. This is assuming $b = user and $e = smartcard id (your variable names don't provide a clue).
Since the arrays are 1:1, the for loop is used to generate a common index into both arrays. For your own benefit (code maintenance), please consider:
- Not using single character variable names. Some have special meaning.
- Renaming your variables to something more meaningful.
- Using lexically scoped (my) variables.
use strict;
use warnings;
my %id_lookup;
my @getuser = `dsquery user -name * -o samid -limit 1000`;
my @getcert = `dsquery usern -name * -o upn -limit 1000`;
for (0 .. scalar @getuser -1){
my $a = $getuser[$_];
chomp $a;
my $b = (split (/"/, $a))[1];
my $c = $getcert[$_];
chomp $c;
my $d = (split (/"/, $c))[1];
my $e = (split (/@/, $d))[0];
$id_lookup{$b} = $e;
# this line adds reverse lookup, if desired
$id_lookup{$e} = $b;
}
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.