[Za-pm] creating new file one line at a time

Anne Wainwright anotheranne at fables.co.za
Sun Mar 7 06:47:07 PST 2010


Hello,

import.txt is one record per line (imports fine into postgresql)
all I want it to add one more '|' delimiter onto the end of each line
before the newline, and save to delimited.txt
but the following perl script does not do this.
the output file is the same as the input

open (IMPORT, "import.txt") or die "file does not exist\n\n";
open (RESULT, ">delimited.txt") or die "cannot create output file\n\n";

while (<IMPORT>) {
    s/(\w)$/$1|/ ;
    print RESULT $_ ;  # write line
}

close (IMPORT) or die "cannot close input file: $!";
close (RESULT) or die "cannot close output file: $!";

any ideas, please?
since we are handling the records one at a time there should be no need
for any modifier?


Anne


More information about the Za-pm mailing list