in reply to How do I assign a variable to the file content?
Update: This post contains some inaccuracies, which Tye points out in a reply below. Read both posts.
To me, this really sounds like you want to accomplish several steps :
The solution is available in the form of the File::CounterFile module. This maintains a counter file which does the counting for you.
If you think rolling your own version is the better solution, keep the following problems in mind :
Update: On rereading your question, I haven't answered your actual questions. Your code
opens the file with the name contained in $counttext and prints the first line of it. The next line in your code,open(COUNTTHIS, "< $counttext") or die "I can't open counttext: $!\n"; print(<COUNTTHIS>);
reads the second line from the file COUNTTHIS, and stores it in $thenumber. What you propably wanted to do was to read a single line from COUNTTHIS, print it, and store it in $thenumber, like this :$thenumber = <COUNTTHIS>; #I thought something like this, but no
print (<COUNTTHIS>); $thenumber = $_; # or, alternatively, like this : $thenumber = <COUNTTHIS>; print $thenumber;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Answer: How do I assign a variable to the file content?
by tye (Sage) on Sep 25, 2000 at 21:26 UTC |