in reply to Problems with 'strict' and variables created on the fly
One way to do this is to use another hash.
There are a few notes in the comments.
#!/usr/bin/perl use strict; my $datafile = "data.txt"; my @now = localtime(time); open(FIL,"<$datafile") or die "Can't open data file: $!\n"; my @data = <FIL>; close(FIL); my %maxCount; my %pages; foreach my $line (@data) { # My is a function and will take a list arguement. my ($timestamp, $page, $moredata) = split('\|',$line); my @hits = localtime($timestamp); # Here I create and preset an array with a variable name defined b +y $page ### @$page = (0,0,0,0) if ($$page[3] eq ''); #Its not quite clear to me when $$page[3] gets set??? Maybe this i +s something like what you want? $pages{$page} = [] unless exists $pages{$page}; if ($hits[7] == $now[7]) { $pages{$page}[0]++; } if ($hits[4] == $now[4]) { $pages{$page}[1]++; } if ($hits[5] == $now[5]) { $pages{$page}[2]++; } $maxCount{'$page'}++; } # Not everyone would endorse this form of list initialisation my ($dAry, $wAry, $mAry) = ('','',''); foreach my $page (keys %pages) { $dAry .= "$pages{$page}[0],"; $wAry .= "$pages{$page}[1],"; $mAry .= "$pages{$page}[2],"; } #... continued exit;
|
|---|