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

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.