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