Just go over the lines. If you see a tool, remeber the relevant information. If you see the user, report the remembered information:
#!/usr/bin/perl
use warnings;
use strict;
my $user = shift;
my ($tool, $issued, $use);
while (<DATA>) {
if (my ($t, $i, $u) = /^Users of (.*?) ?\(total ([0-9]+) licenses
+issued; total ([0-9]+) license/) {
($tool, $issued, $use) = ($t, $i, $u);
}
if (/^$user,(.*)/) {
print "Using $tool since $1 (issued $issued, in use $use)\n";
}
}
__DATA__
Users of spice (total 20 licenses issued; total 0 license in use)
Users of runner (total 10 licenses issued; total 0 license in use)
Users of monitor(total 10 licenses issued; total 2 license in use)
Alex,Mon 20 Jan 2013
Peter,Wed 26 Jan 2013
Users of report (total 15 licenses issued; total 0 license in use)
Users of galaxy(total 10 licenses issued; total 3 license in use)
Martin,Fri 22 Jan 2013
Alex,Mon 21 Jan 2013
Peter,Wed 24 Jan 2013
BTW, is the space after galaxy really missing? If no, you can remove the question marks from the regex.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.
|
|