JusaEngineer has asked for the wisdom of the Perl Monks concerning the following question:
I know what I want to do but I can't find the right syntax to accomplish it. I get pieces of the puzzle, but I can't solve all of them to put them together. So I'll give an example hash of what I have, and the End result I'm looking for, and some pieces that I have solved. I tried to get some answers to single questions but there seem to be so many ways to accomplish them, I don't know how to take the answer and use it to what I understand how to solve my problem. So Here goes, I'm going to try to be as detailed as possible so I'm sorry if it gets long. To get this data I'm parsing a XML file and printing to a .tex file.
My goal is to pars an XML file and pull out all the different types of buttons and numeric entries and collect them in a hash (I know how to do this), Then I need to create a document that will have this data sorted in columns to display on a table. I need to be able to count 14 max per page while going through screens with varying numbers of buttons. At the end of each button that is not the last button I need a partial line "\cline{2-11}". At the end of all buttons of one screen I need a full horizontal Line "\hline". At the end of the page(14lines) I need to enter"\hline\pagebreak". I'm going to change the 14 Line for this to 5 so that not as much data is needed.
Here is my example Hash
use warnings; use strict; use Data::Dumper; my %hash = ( 'Alarms.Alarm Acknowledge' => { 'ScreenName' => 'Alarms', 'Description' => 'Alarm Acknowledge', 'Type' => 'On/Off' }, 'Flow Diagram.Sequence Hold' => { 'ScreenName' => 'Flow Diagram', 'Description' => 'Sequence Hold', 'Type' => 'Momentary' }, 'Flow Diagram.Sequence Advance' => { 'ScreenName' => 'Flow Diagram', 'Description' => 'Sequence Advance', 'Type' => 'Momentary' }, 'Flow Diagram.Sanitize Enable/Disable' => { 'ScreenName' => 'Flow Diagram', 'Description' => 'Sanitize Enable/Disable', 'Type' => 'On/Off' }, 'Trend to USB.Start/Stop Trend Toggle' => { 'ScreenName' => 'Trend to USB', 'Description' => 'Start/Stop Trend Toggle', 'Type' => 'On/Off' }, 'Alarms.Alarm Reset' => { 'ScreenName' => 'Alarms', 'Description' => 'Alarm Reset', 'Type' => 'On/Off' }, 'Alarms.Alarm Trigger' => { 'ScreenName' => 'Alarms', 'Description' => 'Alarm Trigger', 'Type' => 'Momentary' }, ); print Dumper(%hash); print "\n\n\n"; my %ScreenNameCount; $ScreenNameCount{$hash{$_}{ScreenName}}++ foreach keys %hash; my %HashCount; my $Screenkey = 'New'; my $ScreenkeyOld = 'Old'; my @List; my $i = 1; foreach my $key (sort keys %hash) { my $Screenkey = $hash{$key}{'ScreenName'}; my $Description = $hash{$key}{'Description'}; my $Type = $hash{$key}{'Type'}; $HashCount{$Screenkey} = $Screenkey; $HashCount{$Screenkey}= {0 => $ScreenNameCount{$Screenkey}}; if ($Screenkey eq $ScreenkeyOld) { $HashCount{$Screenkey} = {$i => "\\t \\t \\t \\t\& \\mytabhead{$De +scription} \\t\& $Type \\t\\\\ \\hline \\n $i - $Screenkey - $Screenk +eyOld"}; $i++; } else { $HashCount{$Screenkey} = {$i => "\\mytabhead{$Screenkey} \\t\& \\m +ytabhead{$Description} \\t\& $Type \\t\\\\ \\hline \\n $i - $Screenke +y - $ScreenkeyOld"}; $i=1; } $ScreenkeyOld = $Screenkey; } print "\n\n\n"; print Dumper(%HashCount); print "\n\n\n"; print Dumper \%ScreenNameCount; print "\n\n\n";
The .tex file should look what is below. "Trend to USB" has one button, so since the first button is the last it needs to end with \hline. "Alarms" has three and they all fit on the same page so the first 2 buttons end in \cline {2-11} and the last end in \hline. "Flow Diagram" has three buttons also but there is only room for one more button on the page. So the first button will end in \hline \pagebreak thus ending the page and restarting the count to 5. The next two buttons follow the same format, First button on the new page (the Second Flow Diagram Button) will end in \Cline{2-11}, and the last will end in \hline. The first button on the page must also start with "\\mytabhead{Flow Diagram}" verses the three tabs.
\multirow{1}{0.85in}{\mytabhead{Trend to USB}} & \mytabhead{Start/ +Stop Trend Toggle} & On/Off \hline \multirow{3}{0.85in}{\mytabhead{Alarms}} & \mytabhead{Alarm Tr +igger} & Momentary \cline{2-11} & \mytabhead{Alarm Ack +nowledge} & On/Off \cline{2-11} & \mytabhead{Alarm Res +et} & On/Off \hline \multirow{1}{0.85in}{\mytabhead{Alarms}} & \mytabhead{Sequence + Advance} & Momentary \hline\pagebreak \multirow{2}{0.85in}{\mytabhead{Alarms}} & \mytabhead{Sequence + Hold} & On/Off \cline{2-11} & \mytabhead{Sanitize +Enable/Disable} & On/Off \hline
I'm able to get the hash to look like this with the code above:
$VAR1 = 'Trend to USB'; $VAR2 = { '3' => '\\mytabhead{Trend to USB} \\t& \\mytabhead{Start/Sto +p Trend Toggle} \\t& On/Off \\t\\\\ \\hline \\n 3 - Trend to USB - Fl +ow Diagram' }; $VAR3 = 'Alarms'; $VAR4 = { '2' => '\\t \\t \\t \\t& \\mytabhead{Alarm Trigger} \\t& Mom +entary \\t\\\\ \\hline \\n 2 - Alarms - Alarms' }; $VAR5 = 'Flow Diagram'; $VAR6 = { '2' => '\\t \\t \\t \\t& \\mytabhead{Sequence Hold} \\t& Mom +entary \\t\\\\ \\hline \\n 2 - Flow Diagram - Flow Diagram' };
When I want it to look like this:
$VAR1 = 'Trend to USB'; $VAR2 = { '0' => 1, '1' => '\\mytabhead{Trend to USB} \\t& \\mytabhead{Start/Sto +p Trend Toggle} \\t& On/Off \\t\\\\ \\hline \\n 1 - Trend to USB - Ol +d' }; $VAR3 = 'Alarms'; $VAR4 = { '0' => 3, '1' => '\\mytabhead{Alarms} \\t& \\mytabhead{Alarm Trigger} + \\t& Momentary \\t\\\\ \\hline \\n 1 - Alarms - Trend to USB' '2' => '\\t \\t \\t \\t& \\mytabhead{Alarm Acknowledge} \\t& + On/Off \\t\\\\ \\hline \\n 2 - Alarms - Alarms' '3' => '\\t \\t \\t \\t& \\mytabhead{Alarm Reset} \\t& On/Of +f \\t\\\\ \\hline \\n 3 - Alarms - Alarms' }; $VAR5 = 'Flow Diagram'; $VAR6 = { '0' => 3, '1' => '\\mytabhead{Flow Diagram} \\t& \\mytabhead{Sequence + Advance} \\t& Momentary \\t\\\\ \\hline \\n 1 - Flow Diagram - Alarm +s' '2' => '\\t \\t \\t \\t& \\mytabhead{Sequence Hold} \\t& Mom +entary \\t\\\\ \\hline \\n 2 - Flow Diagram - Flow Diagram' '3' => '\\t \\t \\t \\t& \\mytabhead{Sanitize Enable/Disable +} \\t& On/Off \\t\\\\ \\hline \\n 3 - Flow Diagram - Flow Diagram' };
From here my thought was to use the button count ($hash{ScreenName}{0}) for each button to fill in the number on the .tex file (\multirow{???}) and count up to the Button count while also tracking buttons per page and somehow splitting the remaining and putting on the next page.
I know now I'm in way over my head lol please help me get further in this task. I don't want to have to do this manually in a word document. Thanks you for any help.
Mel
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash Manipulation
by Fletch (Bishop) on Jun 07, 2021 at 18:41 UTC | |
by JusaEngineer (Novice) on Jun 08, 2021 at 14:31 UTC | |
|
Re: Hash Manipulation
by haukex (Archbishop) on Jun 08, 2021 at 07:20 UTC | |
by JusaEngineer (Novice) on Jun 08, 2021 at 13:53 UTC | |
by hippo (Archbishop) on Jun 08, 2021 at 15:19 UTC |