I am parsing a log file and trying to validate a value based on conditions within the log file using one of several hash tables. I am not getting any output and do not understand why.

Input file:
CMD, 2018/06/22, 14:21:44, ON, "GOBBLDY GOOK", PRI, "MORE GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, ZELDA, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, YAKOV, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, XAVIER, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, WALTER, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, VICKY, "GOBBLDY GOOK",
CMD, 2018/06/22, 14:21:44, ON, "GOBBLDY GOOK", BU, "MORE GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, ALISTAIR, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, BARB, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, CONNOR, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, DENISE, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, ERIN, "GOBBLDY GOOK",
CMD, 2018/06/22, 14:21:44, OFF, "GOBBLDY GOOK", PRI, "MORE GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, ZELDA, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, YAKOV, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, XAVIER, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, WALTER, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, VICKY, "GOBBLDY GOOK",
CMD, 2018/06/22, 14:21:44, OFF, "GOBBLDY GOOK", BU, "MORE GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, ALISTAIR, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, U, BARB, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, CONNOR, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, DENISE, "GOBBLDY GOOK",
STAT, 2018/06,22, 14:21:44, A, ERIN, "GOBBLDY GOOK",

#! /usr/bin/perl my %dayTable0 = ( "ZELDA" => "U", "YAKOV" => "U", "XAVIER" => "A", "WALTER" => "A", "VICKY" => "A", ); my %dayTable1 = ( "ZELDA" => "A", "YAKOV" => "A", "XAVIER" => "U", "WALTER" => "U", "VICKY" => "U", ); my %nightTable0 = ( "ALISTAIR" => "U", "BARB" => "U", "CONNOR" => "A", "DENISE" => "A", "ERIN" => "A", ); my %nightTable1 = ( "ALISTAIR" => "A", "BARB" => "A", "CONNOR" => "U", "DENISE" => "U", "ERIN" => "U", ); open (FILE, my $file) or die "Can't open $file $!\n"; chomp (my @lines = <FILE>); foreach my $line (@lines) { my @line = split (/,/,$line); if ($line[0] =~ /CMD/) { my $state = $line[3]; my $unit = $line[5]; if ($state =~ /OFF/ && $unit =~ /PRI/) { %table = %dayTable0; } elsif ($state =~ /ON/ && $unit =~ /PRI/) { %table = %dayTable1; } elsif ($state =~ /OFF/ && $unit =~ /BU/) { %table = %nightTable0; } elsif ($state =~ /ON/ && $unit =~ /BU/) { %table = %nightTable1; } else { print "UNKNOWN STATE!! GO FIX SOMETHING!!!"; } } if ($line[0] =~ /STAT/) { my $name = $line[5]; my $status = $line[4]; my $value = $table{$name}; <p> Have tried several variants of above line. $table{ZELDA} gives me +the expected static response<\p> print "LOOKUP STATUS: $value\n"; } }

In reply to Unable to extract value from hash table by NsshB

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.