Solved

Appending!

Posted on 2000-05-16
8
295 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 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
Technology Partners: 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Existing perl code to be changed for ftp to sftp handling 14 261
delete query using perl dbi 3 121
collecting information 2 219
Get a Perl script to return content from a module 7 84
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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

737 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