?
Solved

Appending!

Posted on 2000-05-16
8
Medium Priority
?
297 Views
Last Modified: 2010-03-05
Hi all,
Just a little query today! Can someone tell me what I need to add to the following code so that when the user types in y the file that's been dealt with will be appended to a new file called corpus......

Thanks a mil.!

print "Would you like to include this text in your corpus (Y/N)?\n";
     chomp ($string = <STDIN>);
                     if (uc($string) eq "Y")
                       
0
Comment
Question by:shels
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 240 total points
ID: 2814470
lets assume the file whose info needs to be appended is called sub.txt.


here is the code that will do what you require.

#!/usr/bin/perl

$corpus="/tmp/corpus.txt";
$sub="/tmp/sub.txt";
print "Would you like to include this text in your corpus (Y/N)?\n";
chomp ($string = <STDIN>);

if ($string=~ /^y$/i){
  open (CORP,">>$corpus") || die $!;  ##  Open corpus file in append mode

  undef $/;
  open (SUB,"$sub") || die $!;  ##  Open the other file for reading
  $var=<SUB>; ##  Read entire file in a variable;
  close(SUB);
  $/="\n";

  print CORP $var;  ##  Write the info to the end of corpus!!
  close(CORP);

}
0
 
LVL 84

Expert Comment

by:ozo
ID: 2814814
#or
print CORP <SUB>;
0
 

Author Comment

by:shels
ID: 2816828
Thanks for your help guys my program seems to be running fine, the only problem is when I open the corpus.txt file after running the program nothing has been appended to it!!!  Would you know why???  I can post the program if you need to see the code
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:shels
ID: 2817064
Thanks for your help guys my program seems to be running fine, the only problem is when I open the corpus.txt file after running the program nothing has been appended to it!!!  Would you know why???  I can post the program if you need to see the code
0
 

Author Comment

by:shels
ID: 2817067
Adjusted points from 50 to 60
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2817452
shels,

pl. post you code, so that i can look at it and maybe provide you with a final working solution.

Rgds
0
 

Author Comment

by:shels
ID: 2817693
Hi Maneshr!
I got it working so there's no need, but thanks very much anyway, you were a great help!  
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2818426
cool!!

Regards.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question