in reply to Re^2: Why am I getting Can't use string (<string value>) as an ARRAY ref wile "strict refs" in use
in thread Why am I getting Can't use string (<string value>) as an ARRAY ref wile "strict refs" in use
If you want to build the hash
$metrics{$product}{$date}{$hour}{$user} = $val;Then $metrics{$product}{$date} has to be a hash reference. It can't be used the store the day. If you need to store the day use a separate hash
$calendar{$date} = $day;
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $day; my $date; my $time; my $product; my %metrics; my %calendar; my $infile = 'C:/SCCI/scci_clearcase/All_license_info_Jan2019_sample.t +xt'; open LICIN, '<',$infile or die "COuld not open $infile : $!";; while (my $str = <LICIN>) { chomp $str; next unless $str =~ /\S/; #skip blanks #Flexible License Manager status on Wed 1/2/2019 07:00 if ($str =~ /^Flexible License.* (...) (\d+\/\d+\/\d\d\d\d) +(\d\d:\ +d\d)$/) { $day = $1; $date = $2; $time = $3; $calendar{$date} = $day; next; } if ($str =~ /Users of (.*):/) { $product = $1; print "Parsing $product section\n"; } next unless defined $product; # amlove unodecx86 WI_zfTVVG-n7Ph2jhkOo #u#amlove#u# (v1.0) (unod +ecx80/27000 615), start Wed 1/2 6:56 (linger: 1800) if ($product eq 'ClearCase'){ next if $str =~ /ClearCase|floating license/; #skip unwanted lines $str =~ s/^\s+//; my ($user,$sysacc,$origsys,undef) = split / /,$str,4; $metrics{$product}{$date}{$time}{$user} = 'X'; } } close LICIN; print Dumper \%metrics; # # print hash table # my $mydebug1 = 1; if ($mydebug1) { for my $k1 (keys (%metrics)) { print "k1 = $k1 \n"; for my $k2 (keys(%{ $metrics{$k1} })) { print "k2 = $k2 \n"; for my $k3 (keys(%{ $metrics{$k1}{$k2} })) { print "k3 = $k3 \n"; for my $k4 (keys(%{ $metrics{$k1}{$k2}{$k3} })) { print "k4 = $k4 \t k4val = $metrics{$k1}{$k2}{$k3}{$k4}\n"; } } } } }
|
|---|