Solved

Appending!

Posted on 2000-05-16
8
291 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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 …
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now