Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with appending to a:\ 2

Status
Not open for further replies.

MinniePerl

Technical User
Apr 19, 2001
7
US
#open (FIVEWORDS, ">>a:\\test.txt"; doesn't append any data to a:\test.txt
#and I can't figure out what the problem is. Any suggestions? Thanks much.

while ($quit ne "q")
{
print "Enter any word and return: "; #user input
chomp ($word1=<STDIN>); #Assign input
print &quot;Enter another word and return: &quot;; #user input
chomp ($word2=<STDIN>); #assign input
print &quot;Enter another word and return: &quot;; #user input
chomp ($word3=<STDIN>); #assign input
print &quot;Enter another word and return: &quot;; #user input
chomp ($word4=<STDIN>); #assign input
print &quot;Enter the fifth and final word of this group and return: &quot;;
#user input
chomp ($word5=<STDIN>); #assign input


@words=join(&quot;, &quot;,( &quot;$word1&quot;, &quot;$word2&quot;, &quot;$word3&quot;, &quot;$word4&quot;, &quot;$word5&quot;));

open(FIVEWORDS, &quot;>>a:\\test.txt&quot;);
@words=<FIVEWORDS>;
$_=&quot;@words&quot;;

close(FIVEWORDS);
print$_;



print &quot;Enter q to quit or press return to enter another group
of five words: &quot;; #quit or continue
chomp ($quit=<STDIN>);

<STDIN>

}

 
Well, seeing as you don't have a closing parenthese for the open() function, I would try this:

open (FIVEWORDS, &quot;>>a:\\test.txt&quot;);
^ -- add paren there. vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
Hehe, sorry, the little caret should be pointing to the ending parenthesis at the end of the function.

Hope this helps,
-Vic

vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
So it should look like:
open(FIVEWORDS, &quot;>>a:\\test.txt.&quot;));

You'll have to forgive me. This stuff is very new to me. That didn't make sense to me. Thanks just the same though.
 
well, you're on the right track, but you have a few mistakes.

'join' takes a list of things, and then returns a scalar value corresponding to each of the things in the list separated by the first string supplied. you will call it like this:[tt]
$string = join(&quot;, &quot;, $word1, etc.);
[/tt]

to put data into a file like you're trying, you need to print TO the file, like this:[tt]
print OUTFILE &quot;this is some text\n&quot;;
[/tt]

when you call print, or any function, you shoud leave a space between it and it's first argument. or you can start paratheses immediately after it.

when you open up a file for appending, you cannot read from it. if you are trying to read from it, you need to open up the file for reading and writing:[tt]
open(FILE, &quot;>>+file.txt&quot;);
[/tt]
however, opening a file for appending sets the file position the the very end of the file - ie when you try to read from it, there will be no data. you'll have to first append the data to it(with print), and then reset the file position to where ever you want to read from - in bytes... if you want to read in all of the file, use this before you try to read from it:[tt]
seek FILE, 0, 0;
[/tt]
read 'perldoc -f seek' for more on what that's doing. and note that calling '<FILE>' is a read from the file.
i'm not sure you're actually wanting to read from the file, so this probly isn't an issue and you should just ignore this paragraph.

HTH
&quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top