Hi Monk

I require a parsing help when parsing and extracting info from a file of following pattern. Please refer to the content in between the '###' boundaries below

####################
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
######################

The file content shows how many licenses for some tools (spice,ruuner,monitor,galaxy) are issued,how many are in use and who all are using if in use.

My task is to extract the info for a given username (say Alex), which all licenses are in use and their availability. If no license is used for that user, then give nothing.

Please help me how can I extract that info for a user only when some licenses are in use.

I have tried to come up with this following code, but need help to go ahead :

while (<FILE>) { if(/^Users of (\w+):/) { my $line = $_; my $licName = $1; my ($totalIssued,$inUse); if ($line =~ /total of (\d+) licenses issued/) { $totalIssued = $1 ; print "Total : $totalIssued \n"; } if ($line =~ /total of (\d+) licenses in use/) { $inUse = $1 ; print "In Use : $inUse \n"; } } }

Thanks.


In reply to parsing help required by ghosh123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



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