UPDATE: SOLUTION PROVIDED

I have a written a working Perl script (my first one). The interpreter complains when I turn on 'use strict'. I get the following error message: "Global symbol $files requires explicit package name at...line 19...line 20...line 24".

My code:

#!/usr/bin/perl use warnings; use strict; my @files; my $downloadpath = "/home/content/c/r/e/creatingzion/html/downloads"; my $timestamp = time(); my $modified_time; #[9] in the list of file attributes. my $age_of_file; my $time_to_live = 3600; #return a list of all the mp3 files in the downloadpath opendir(DIR, $downloadpath); @files = grep(/\.mp3$/,readdir(DIR)); closedir(DIR); #end comment #compare each file's last modified time with the current time and dele +te any files older than the time to live in seconds. foreach $files (@files) { $modified_time = (stat($downloadpath."/".$files))[9]; print $modified_time; $age_of_file = $timestamp - $modified_time; if($age_of_file >= $time_to_live) {unlink($downloadpath."/".$files);} } #end comment

The only thing I can think of and only thing my research indicates is that I need to use a lexical variable. But I'm doing that already.

UPDATE: Thank you both for you help.


In reply to Global symbol .... requires explicit package name at by ZETZ

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.