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!

Sending data to a:\ and bringing back with substitutions 1

Status
Not open for further replies.

MinniePerl

Technical User
Apr 19, 2001
7
US
Thanks mucho to stillflame on my last problem with this.

This program is supposed to ask the user to input five words. Then the input is to be sent to a:\. Next the five words are supposed to be brought back with substitutions made to them. It does all of that, but if the user inputs two or more sets of five words, it puts them all on one line. How do I get five words per line, both in a:\ and when it prints them back out on the screen.
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=(&quot;$word1&quot;, &quot;$word2&quot;, &quot;$word3&quot;, &quot;$word4&quot;, &quot;$word5&quot;);
#assign words to array
$wordbreak=(join(&quot;, &quot;, @words)); #join words with ,
open(FIVEWORDS, &quot;>>a:\\test2.txt&quot;); #send data to a:

print FIVEWORDS $wordbreak;

close(FIVEWORDS);




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

print &quot;Here are the results:\n&quot;;



}

open (OLDFILE, &quot;<a:\\test2.txt&quot;); #retrieve data
@databack=(split (/, /, <OLDFILE>)); #split data with ,
$_= &quot;@databack&quot;;
close(OLDFILE);
s/a/x/ig;
print $_;

<STDIN>;




 
sloppy way, don't 'chomp' the fifth word. that's a little bit hard to trace, so it'll be easier if you just add this line:[tt]
$wordbreak .= &quot;\n&quot;;
[/tt]
right after you first make it. this adds a newline character to the end of the text. oh, wait, you're in windows aren't you... change that to:[tt]
$wordbreak .= $/;
[/tt]
and that will work for sure.

you may also want to re-evaluate the structure of what's going on at the end of the program. it prints &quot;Here are the results&quot;, but then ends the block, so the results only get printed if the user just quit, but 'here are the results' will get printed every time.
&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