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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Temporary usage of RAM memory by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found