kramdeav has asked for the wisdom of the Perl Monks concerning the following question:
$printline="O*N%1d5TG%5d ,CLS=%.8s,XXX,BAT=, + \n"; $dest_mailbox=shift(@ARGV); $file=shift(@ARGV); $message_class=shift(@ARGV); # Set up a temp file as a holding file for valid lines $rand = int(rand(10000)); $tempfile="$file" . "$rand"; print "!Creating temp file: $tempfile!\n"; while (-f $tempfile) { $rand = int(rand(10000)); $tempfile="$file" . "$rand"; } # # Open the input file and temporary file # open (FILE, "$file") or &exit_with_error("!Error opening file for read +: $file!\n"); open (TEMP, ">>$tempfile") or &exit_with_error("!Error opening file fo +r write: $tempfile!\n"); # $total_lines=0; $hort=0; ** Prints to temp file the header record ** printf TEMP $printline,$hort, $dest_mailbox, $message_class; ** Prints to temp file the data from another file ** while (<FILE>) { $total_lines++; chomp($_); print TEMP "$_\n"; $data_lines++; } } ** Prints to TEMP file the trailer record. $hort=9; printf TEMP $printline, $hort, $dest_mailbox, $message_class;
The whole idea behind this code is to take a file that has data records and insert header and trailer records. The data moves over just fine, but the header and trailer records have a small square box which should be a new line character but is not. The file needs to have a the data on the next line. For some reason the temp file does not like the \n on the header and trailer record.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: My Script is saving a New Line Character as an Unreadable character.
by Old_Gray_Bear (Bishop) on Feb 22, 2014 at 16:04 UTC | |
|
Re: My Script is saving a New Line Character as an Unreadable character. (binmode)
by Anonymous Monk on Feb 21, 2014 at 23:14 UTC | |
|
Re: My Script is saving a New Line Character as an Unreadable character.
by locked_user sundialsvc4 (Abbot) on Feb 24, 2014 at 12:53 UTC |