I'm a little confused here -- sorry... When you say "it works fine when I don't use strict", what exactly do you mean by "works fine"? Does it actually do what you intend it to do? Or is it "fine" just because it doesn't report any errors?

I'm curious, because this part:

(my $timestamp, my $page, my $moredata) = split('\|',$line);
seems to conflict harshly with this part, which comes just two lines later:
@$page = (0,0,0,0) if ($$page[3] eq '');
BTW, that looks like you're doing a test on an uninitialized array element -- nothing could have been assigned to $$page[3] at the time it's evaluated in the "if" statement here, so the test is always true.

Then there's this third part a few lines later, which could coexist with either of the previous two:

$maxCount{'$page'}++;
The first part assigns a string to a scalar variable $page. The second part treats $part as a reference to an anonymous array, and if this works, it's because the earlier string value has been replaced (obliterated) by the array reference. The third part "stringifies" the array reference and uses it as a hash key.

So, okay, I guess it might work fine without "use strict"; the point is that strings read from input data have nothing to do with the names of variables here. When you use strict, the anon.array held in $page goes out of scope, has no other references to its content, and is reaped.

I would propose an alternate form for the first for loop that would make more sense: creating a new array, and setting the value of a hash element to be a reference to that array, or something of that nature -- but I can't quite make out your intentions in that code... Still, here's a try:

foreach my $line (@data) { (my $timestamp, my $page, my $moredata) = split('\|',$line); my @hits = localtime($timestamp); # Here I create and preset an array with a variable name defined b +y $page my @counters = (0,0,0,0); if ($hits[7] == $now[7]) { $counters[0]++; } if ($hits[4] == $now[4]) { $counters[1]++; } if ($hits[5] == $now[5]) { $counters[2]++; } $maxCount{$page} = \@counters; } my $dAry = ""; my $wAry = ""; my $mAry = ""; foreach my $page (keys %maxCount) { my @counters = @{$maxcount{$page}}; $dAry .= "$counters[0],"; $wAry .= "$counters[1],"; $mAry .= "$counters[2],"; }
Let me stress that this suggestion only serves to make a sensible use of variables and references -- I have no confidence that it would actually do whatever it is you're trying to do.

In reply to Re: Problems with 'strict' and variables created on the fly by graff
in thread Problems with 'strict' and variables created on the fly by nedals

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.