One a file and save the contents in another file?

Heres the file And the data is being Parsed but the output is not beign stored in the file... Could someone please help?

The code should take out all the stop words and then store rest of the data in a  url.parse.
I and see the result on the sommand prompt but not in the file....


#!/usr/bin/perl

open KW, 'stop_words';
@kw = map {chop;$_} <KW>;
close KW;

#form RE

$re = join '\b)|(\b','(\b', @kw,'\b)';

open TXT,'test.out';
while(<TXT>){
  s/$re//goi;
  $content= print $_;
}

print $content;
cp_to_file($content, "url.parse");
print "\n\n\n";
# copies text to file

sub cp_to_file {
    my ($text, $to_file) = @_;

    open(OUT, ">" . $to_file);
    print OUT $text;
    close(OUT);
}
sdesarAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
What did you change?
It sounds like you may have done something like

while(<TXT>){
  s/$re//goi;
  $content .= print $_;
}

instead of

while(<TXT>){
  s/$re//goi;
  $content .= $_;
}
0
 
lorentgCommented:
1 point?
0
 
ozoCommented:
#perhaps you meant to say
$content .= $_;
#instead of
$content= print $_;
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
sdesarAuthor Commented:
Thanks OZO....

Your suggestion worked as always... however... I am getting a bunch of  
11111111111111111
at the end of file...

What could I do to get rid of those  1s?


0
 
sdesarAuthor Commented:
this is what I did on the command line --
$perl  parse2file

The words are parsed correctly but the data appears on the command line and the output file
url.parse only has a bunch of 11111111111s


The input file is test.out
the output file is url.parse


What wrong?
0
 
sdesarAuthor Commented:
Thanks OZO ...for all your help...

I want to give you excellent points for your work.

However, there seems to be a bug and points will go to someone else... i have reported it to EE.
I hope to hear from them soon.


0
 
sdesarAuthor Commented:
Thanks OZO!!
0
All Courses

From novice to tech pro — start learning today.