Solved

Appending!

Posted on 2000-05-16
8
293 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
  • 4
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 60 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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