Hi,

Newbie here. I am writing a program that takes a file that has two columns
of words, extracts the second column, then saves the original file with only
the data in the first column.

Question #1 - would it be better to do this w/ the split or s/// functions ?
Question #1 - how do I write back the results to the original file ? I tried
using +< or > but all these do is add to the original file and not re-write
it.
if I open it like this >> then it erases the file first and I get no data.

my source file (searchandreplace.txt) looks like this:
XXXXX YYYYY
XXXXX YYYYY
XXXXX YYYYY

my code looks like this:

my $source_file = "searchandreplace.txt";
 open(SOURCE, "+<$source_file") || die "can't open file: $1";
 flock(SOURCE,2);
 foreach  ( <SOURCE> ) {
  s/\s+\w+//;
  print SOURCE  ;
 }

after I run the program it looks like this:
XXXXX YYYYY
XXXXX YYYYY
XXXXX YYYYY
XXXXX
XXXXX
XXXXX

instead of what I want
XXXXX
XXXXX
XXXXX


thanx for your patience.

AN



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to