thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I have implemented a short sample code of question for better explanation.
I am trying to use a string storing an integer that I want to increment when ever I would be calling my sub program.
My solution so far is storing the value on a .txt file reading the value and icrementing it on every round. Sample of working code is provided under.
I am wondering if there is a possible solution, to store the value to an allocated memory, that will be not used until I calle it again. I want my subprogram to be able to complete the process and not loose the value from the memory. I was even thinking in worst case scenario to use MySQL database but I want to avoid this solution.
#!/usr/bin/perl use strict; use warnings; my @words; my $word; my $text; my $file = "test.txt"; open (DATA, "+<", $file) or die("Could not open file: ".$file.". $!\n"); sub add { print "I am in\n"; while( <DATA> ) { chomp; @words = split(''); foreach $word (@words) { print "This is word: ".$word."\n"; $text = $word + 1; print "This is the new word: ".$text."\n"; } } } &add(); print DATA "".$text."\n"; close (DATA);
Thank you for your time and effort.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Temporary usage of RAM memory
by BrowserUk (Patriarch) on Apr 10, 2014 at 22:45 UTC | |
by davido (Cardinal) on Apr 11, 2014 at 00:46 UTC | |
by fullermd (Priest) on Apr 11, 2014 at 05:16 UTC | |
by davido (Cardinal) on Apr 11, 2014 at 06:18 UTC | |
by thanos1983 (Parson) on Apr 11, 2014 at 08:47 UTC | |
by thanos1983 (Parson) on Apr 11, 2014 at 08:39 UTC | |
Re: Temporary usage of RAM memory
by Anonymous Monk on Apr 10, 2014 at 21:35 UTC | |
by thanos1983 (Parson) on Apr 11, 2014 at 08:34 UTC | |
Re: Temporary usage of RAM memory
by zentara (Archbishop) on Apr 11, 2014 at 10:12 UTC | |
by thanos1983 (Parson) on May 08, 2014 at 19:20 UTC |