Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^7: Rolling variable

by james28909 (Deacon)
on Jul 30, 2015 at 15:36 UTC ( [id://1136884]=note: print w/replies, xml ) Need Help??


in reply to Re^6: Rolling variable
in thread Rolling variable

I would like to keep only the last 8 counts, meaning throw away the oldest data & just keep the last 8 records.

This could honestly be open to interpretation. I took it as what he really needed was the last 8 records thats currently in the directory. Anyways, Thanks for pointing that out, I retract any and all suggestions.

EDIT: Hi James, Rata, Thanks for the inputs. However, I thin k this will work in a single run of the script

Even the OP stated this would work, but he needed it to run every hour, so I modified it somewhat to show him another way. I am only giving suggestions/opinions/options in hopes it will make him think/tinker more and figure it out on his own. I also search for code and modify it as I need IF I cant figure it out myself.

Replies are listed 'Best First'.
Re^8: Rolling variable
by fishmonger (Chaplain) on Jul 30, 2015 at 16:00 UTC

    You left out a key portion of that quote.

    (please correct me if I'm wrong)

    The OP's assumption was wrong and your update should have included the correction.

    You also skipped over his last sentence.
    So I was thinking to save the counts in a file

    And why copy the array resulting in 3 arrays only differing in the order of the elements? Only 1 array is needed. The others IMO just add unnecessary obfuscation and inefficiency.

      If he wanted to save the count "8" into a file, what would be the point? If he wanted the last 8 counts of the function, it will always return "8" would it not? If that was the case, he could just set $count to '8' and be done with it.

      Anyways, im not going to argue with anyone, it was merely an opinion/suggestion that I posted earlier and was not meant to start a war over something that could have been interpreted 5 different ways. Thanks for your insight though, I will keep it in mind for future reference.

        I believe the OP wanted effectively to list the files in a directory, get the count of the number of files, and save this number in a file. Per my recommended approach (Tie::File), each line in the store file would contain an integer of the number of files. This file would have eight lines (one per hour apparently). After the file hits eight lines, the top one (oldest) gets shifted off, and the most recent goes to the bottom.

        If he wanted to save the count "8" into a file, what would be the point? If he wanted the last 8 counts of the function, it will always return "8" would it not?

        You definitely are cherry pinking and misreading the OP's question and statements. He doesn't want to track the number of times a function or script is called. He want's to track the number of files in a directory over an 8 hour period. He didn't say his reason why, but that is what he wants.

        None of us are wanting or trying to argue. We're just trying to clear up some misunderstandings.

        Both mine and stevieb's suggestions accomplishes what the OP asked. Yours unfortunately does not.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1136884]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-03-28 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found