http://qs321.pair.com?node_id=165407

So, there I was... sitting at a perl user group meeting last night and we were going over some OS admin scripts one of the members had written. He then started talking about writing yet another "mount point percent free" script, but where most scripts compare the current space utilization against one or more thresholds, he was interested in watching the growth rate of the mount points. This started me thinking about collecting used space statistics over time for all the mount points on a system, using regression to determine the "normal" growth, and then sending notifications when growth is outside the "normal" range.

You know how your mind starts to wander after working all day? When I started thinking about storing the data points, my mind went down an unexpected path -- could I write a single script which would not only contain the perl source, but would also contain the configuration information and serve as the repository for the historical trend data? (Please note: even in this strange state, I did not expect to store a "lot" of data, but rather, maybe 48 or so data points for each mount point.)

I guess all this rambling brings me to my real thoughts: For me, at least, this has become an "interesting... see what I can do" problem; has anyone else manipulated a script's source and stored changing data after the __DATA__ token?

  • Comment on Storing changing data within a script after the __DATA__ token

Replies are listed 'Best First'.
Re: Storing changing data within a script after the __DATA__ token
by mirod (Canon) on May 09, 2002 at 15:57 UTC

    Yes, TheDamian and Brian Ingerson wrote Inline::Files, which allows you this and much more, like having several virtual files instead of just one.

      That reminds me of last years TPC. In one of TheDamian's sessions (I think it was 'The Conway Channel') he was talking about how he wrote Inline::Files. At this point Ingy stood up at the back of the hall and shouted something to the effect of "Excuse me, who wrote Inline::Files?". TheDamian made some form of 'off-the-cuff' remark and Ingy stormed out of the session. All harmless fun (I think...) and rather amusing :-)

      -- vek --

        You missed the best part then: this was just a set-up. Damian and Brian spent the whole week pretending they had had an argument, just to prepare the last lightning talk, were Damian started explaining how he created Inline::Files, just for Brian to step in and argue that _he_ was the creator, and they spent 5 minutes yelling at each other... in Shakespearian English! That was really funny.

Re: Storing changing data within a script after the __DATA__ token
by jynx (Priest) on May 09, 2002 at 19:47 UTC

    shamless plug: a different way to do it

    That's probably not the way you want to do it at all, but it works, if nothing else. What i did was: read the file into an array, pop off the lines from the end until i found the __END__ token, write over the original file (look at the c subroutine in the spoiler for the code). Since i had already read the data after the __END__ token before i wasn't missing anything, but one could also store the data while popping it off the array.

    There are numerous ways to do it, and this is provided as a mere example of that. But really, i would suggest going with TheDamien's (and TheBrian's) module over this method for many reasons (most notably of which is maintainability).

    jynx

Re: Storing changing data within a script after the __DATA__ token
by cowens (Beadle) on May 09, 2002 at 18:50 UTC
    The only downside I can see to this is that tripwire and its ilk would start complaining.