Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

keeping something in memory after the end of script

by swissknife (Sexton)
on Apr 15, 2016 at 10:34 UTC ( [id://1160504]=perlquestion: print w/replies, xml ) Need Help??

swissknife has asked for the wisdom of the Perl Monks concerning the following question:

Dear Experts,

I am writing a script to monitor the change in checksum of a file. idea is to get the checksum id and store it somewhere and then in next run compare it with previously stored value and if difference alert it to Admin.

A simple solution is using file handling but what if someone change the content of this file once the new checksum is created.

So i was wondering is there a way to store this value directly in memory or somewhere more secure and then read it for comparison.

Thank You.

  • Comment on keeping something in memory after the end of script

Replies are listed 'Best First'.
Re: keeping something in memory after the end of script
by Corion (Patriarch) on Apr 15, 2016 at 10:41 UTC

    There is no way to keep data "in memory" without also having a process attached to it.

    You will either have to stick the data into a file or into some kind of database.

    If you want to be notified of file changes, keep a process running and look at the inotify modules.

Re: keeping something in memory after the end of script
by BrowserUk (Patriarch) on Apr 15, 2016 at 11:30 UTC

    On Windows you might consider the registry (via Win32::Registry).


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: keeping something in memory after the end of script
by clueless newbie (Curate) on Apr 15, 2016 at 10:58 UTC
    You could send it to and retrieve it from a clipboard.
Re: keeping something in memory after the end of script
by NetWallah (Canon) on Apr 15, 2016 at 17:46 UTC
    If the "Next run" is started from the same shell, or a child of that shell, you could use "export"ed environment variables to persist data, as suggested here.

            This is not an optical illusion, it just looks like one.

      Not really (at least, not without some sort of nutso magic trick). The shell would be the parent process of your script; you can't mess with your parent's environment.

        Point taken (++), but the magic is not too achene:
        ~$ chksum=$(perl -e'print qq|Set by perl|'); echo BASH says chksum is +$chksum BASH says chksum is Set by perl

                This is not an optical illusion, it just looks like one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2024-04-25 01:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found