perlquestion
rsriram
<p>Hi all</p>
<p>I am working on a coded file, which has the format as follows</p>
<p><code><act>Key</act><emp>3384</emp><job>78082</job><chap>6</chap><pg>20</pg><time>0.7</time><prod>114.285714285714</prod>
<act>Reconcile</act><emp>3017</emp><job>78062</job><chap>2-7</chap><pg>0</pg><time>1.4</time><prod>Insufficient Information</prod>
<act>Training</act><emp>3384</emp><job>77654</job><chap>-</chap><pg>0</pg><time>5.1</time><prod>Non-Billable</prod>
<act>Management</act><emp>3017</emp><job>77893</job><chap>-</chap><pg>0</pg><time>4.4</time><prod>Non-Billable</prod>
<act>Break</act><emp>3379</emp><job>33843</job><chap>-</chap><pg>0</pg><time>0.2</time><prod>Non-Billable</prod>
<act>Excess overload</act><emp>3379</emp><job>77570</job><chap>14</chap><pg>1</pg><time>0.5</time><prod>6.66666666666667</prod>
<act>Management</act><emp>3123</emp><job>88898</job><chap>-</chap><pg>0</pg><time>0.5</time><prod>Non-Billable</prod>
<act>Management</act><emp>3123</emp><job>22304</job><chap>-</chap><pg>0</pg><time>0.3</time><prod>Insufficient Information</prod>
<act>Management</act><emp>3123</emp><job>11121</job><chap>-</chap><pg>0</pg><time>1.4</time><prod>Non-Billable</prod>
<act>Adapt</act><emp>3123</emp><job>78143</job><chap>08-</chap><pg>0</pg><time>0.3</time><prod>Insufficient Information</prod>
<act>Import</act><emp>3417</emp><job>76584</job><chap>App K</chap><pg>4</pg><time>1.0</time><prod>11.4285714285714</prod>
<act>Break</act><emp>3123</emp><job>22732</job><chap>-</chap><pg>0</pg><time>0.4</time><prod>50.65687</prod>
<act>key</act><emp>3123</emp><job>78143</job><chap>08</chap><pg>0</pg><time>3.3</time><prod>45.5544</prod>
<act>Supervision</act><emp>3192</emp><job>54281</job><chap>-</chap><pg>0</pg><time>4.0</time><prod>Non-Billable</prod></code></p>
<p>In the above file, <code><emp></code> is the employee number and I want to print the average productivity <code><prod></code> of every <code><emp></code>. This should not consider if there is no productivity number specified in the <code><prod></code> element (eg. Non billable or Insufficient information). The output should be similar to</p>
<code>3384 - 114.285714285714
3379 -
3017 -
3379 - 6.66666666666667
3123 - 48.105635
3417 - 11.4285714285714
3192 - </code>
<p>I tried the following code, but I could not get it.
<p><code>while(<F5>)
{
for my $a(0..$#inlst)
{
if($_ =~ /<emp>@inlst[$a]<\/emp>/)
{
$_ =~ /<prod>(.+?)<\/prod>/g;
$prod=$1;
if($prod > 0)
{
$sum=$sum+$prod;
}
}
}
print "@inlst[$a]\t$sum\n";
}
}</code>
<p><code>@inlst</code> will contain all the employee codes in it. Can anyone help me on this?</p>