
Tejas
User
Jul 11, 2016, 12:49 PM
Post #1 of 2
(1753 views)
|
Reading a file from reverse and Storing the data
|
Can't Post
|
|
This CODE reads the file from top to bottom as usual my requirmnet is to read it reverse and store the data undr the regex headings below.
my $CURRENT_REPORT_PART1_REGEX = 'Start of CURRENT Report Part 1 Summary'; my $END_SEARCHING_REGEX = 'Retired Alert IDs Since Last Interval'; sub MyFunc { my $expAddress = 780200700103; my @fileData = <DATA>; foreach my $input_line (@fileData) { if ($input_line =~ m/$CURRENT_REPORT_PART1_REGEX/) { $TableName = $CURRENT_REPORT_PART1; next; } elsif ($input_line =~ m/$END_SEARCHING_REGEX/) { $currentTableName = ""; $filteredTableEntriesMap{$REPORT_PART1} = [@ReportP1DataList]; return (true, \%filteredTableEntriesMap); } if ($TableName eq $CURRENT_REPORT_PART1) { if (does_ReportP1_dataEntry_contains($input_line, $expAddress)) { push (@ReportP1DataList, $input_line); } } } outputLog ("STEP FAILED: report file is empty or no expected data is found"); return (false, \%filteredTableEntriesMap); } sub does_ReportP1_dataEntry_contains { my ($line, $CURRENTNo) = @_; return ($line =~ m/^\s*$\s+/); } __DATA__ Retired Alert IDs Since Last Interval Summary at CST Time: Wed Oct 14 14:32:34 2015 ------------------------------------------------------------------------------------- ----NO ALERTS RETIRED---- ------------------------------------------------------------------------------------- Start of Current Report Part 1 Summary ----------------------------------------------------------------------------------------------------------------------------------------------- Current Current Mode Link State Comm Lvl ----------------------------------------------------------------------------------------------------------------------------------------------- 780200700103 ON DEMAND MONITORING 99.36 ----------------------------------------------------------------------------------------------------------------------------------------------- Start of Current Report Part 2 Alert Summary ------------------------------------------------------------------------------------------------------------------------------ Current Current Mode Link State ------------------------------------------------------------------------------------------------------------------------------ ----No Currents Have Active Alerts---- -------------------------------------------------------------------------------------------------------------------------------------------------------------------- Active Current Alert Summary at UTC Time: 1444852174 CST Time: Wed Oct 14 14:32:34 2015 to Wed Oct 14 14:49:34 2015 -------------------------------------------------------------------------------------------------------------------------------------- Current Comm Alert ID Delay Alert ID Seq Alert ID Overall Alert ID Freq Alert ID WSBE Exec Alert ID Cell Tx Alert ID -------------------------------------------------------------------------------------------------------------------------------------- ----No Active Alerts For Any Current---- ----------------------------------------------------------------------------------------------- Start of Current/Base Station Link Report Summary Part 1 at UTC Time: 1444852174 CST Time: Wed Oct 14 14:32:34 2015 to Wed Oct 14 14:49:34 2015 ------------------------------------------------------------------------------------------------------------------------------------------------ Current Base Station Current Mode Link State Comm Lvl ------------------------------------------------------------------------------------------------------------------------------------------------ 780200700103 up.v.000315 ON DEMAND MONITORING 99.36 Start of Current/Base Station Link Duplicate Report Summary at UTC Time: 1444852174 CST Time: Wed Oct 14 14:32:34 2015 to Wed Oct 14 14:49:34 2015 ---------------------------------------------------------------------------------------------- Current Base Station Current Mode Link State Duplicate Message Count ---------------------------------------------------------------------------------------------- ----No Links with Duplicates---- ------------------------------------------------------------------------------------------------------------------------------------------------ Start of Current/Base Station Link Report ------------------------------------------------------------------------------------------------------------------ Current Base Station ------------------------------------------------------------------------------------------------------------------ ----No Links Have Active Alerts---- ------------------------------------------------------------------------------------------------------------------ Active Link (Current/Base Station) Alert Summary ------------------------------------------------------------------------------------------------------------------------------------------- Current Base Station ------------------------------------------------------------------------------------------------------------------------------------------- ----No Active Alerts For Any Link---- ------------------------------------------------------------------------------------------------------------------------------------------- Active Alert ID Summary at CST Time: Wed Oct 14 14:49:34 2015 ------------------------------------------------------------------------------------- ----NO ACTIVE ALERTS---- ------------------------------------------------------------------------------------- Retired Alert IDs Since Last Interval Summary at CST Time: Wed Oct 14 14:49:34 2015 ------------------------------------------------------------------------------------- 1 2 3 ------------------------------------------------------------------------------------- The above code stors the info when file reads top to bottom I would want to read th file in reverse way and store the values below that heading in a data structure as shown above. I would want to read the file from last to first and stop when the regex matches END_SEARCHING_REGEX Ultimately, The output should be whethr $expAddress is available in the table or not. Any Suggstions, Thanks Tejas
(This post was edited by Tejas on Jul 11, 2016, 12:56 PM)
|