rkrish has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm calling an API internally from a script and need to grep few values from the output of API,when the call is being made to an API,it could take some amount of time to get the output,but my code was trying to grep values from the output file before the output is generated.Is there any way to do further processing only after output is generated?
while ( @accumRow = $getAccums->fetchrow_array() ) { push(@accums,@accumRow); ($currAccumId) = @accumRow; print ("currAccumId = @accumRow \n"); $getSbscrpidFrmAccum->bind_param(1,$currAcct); $getSbscrpidFrmAccum->bind_param(2,$currAccumId); $getSbscrpidFrmAccum->execute()|| logDBIError(" execut +e failed for fetching sbscrpId from Accum of the Account $currAcct + "); while (@sbscrpRow = $getSbscrpidFrmAccum->fetchrow_arr +ay() ) { ( $sbscrp_id ) = @sbscrpRow; } $xmlFile = "GetUsgSummary_" . $currAcct ."_".$currAccu +mId.".xml"; createXmlForUpd( $xmlFile, $currAcct,$sbscrp_id ); $retValue = invokeServer( $currAcct , $xmlFile,$currAc +cumId ); if ( $retValue == ERROR ) { logMessage( "API call failed for acct $currAcct wi +th accumId @accumRow of subscriber $sbscrp_id \n"); } else { open(FILE,"<","$retValue"); my $accumId = 0; my @inclUnits = (); my ($inclUnits); my ($inclUnitsUsed); my ($shared); while(<FILE>) { if($_ =~ m/accumId="$currAccumId"/) { @inclUnits = split(/ /,$_); ($inclUnits) = grep(/inclUnits=/, @inclUni +ts); $inclUnits =~ s/inclUnits="([^"]+)"/$1/g; ($inclUnitsUsed) = grep(/inclUnitsUsed=/, +@inclUnits); $inclUnitsUsed =~ s/inclUnitsUsed="([^"]+) +"/$1/g; ($shared) = grep(/shared=/, @inclUnits); $shared =~ s/shared="([^"]+)"/$1/g; logMessage( "accumId=$currAccumId : $inclU +nits : $inclUnitsUsed : $shared\n"); } } close(FILE); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wait for the response of API
by CountZero (Bishop) on Dec 24, 2012 at 11:16 UTC | |
by rkrish (Acolyte) on Dec 24, 2012 at 11:32 UTC | |
by CountZero (Bishop) on Dec 24, 2012 at 12:06 UTC | |
|
Re: Wait for the response of API
by NetWallah (Canon) on Dec 24, 2012 at 22:40 UTC |