0

I am trying to write a script to rename files based on a given list. To test to make sure the list is read correct, I have:

print("start\n");
open(READFILE, "<prune.txt") || die "Couldn't open file";
print("file open\n");
while ($curline = <READFILE>){

print "$curline\n";
}
close (READFILE);

if my list file is

P_4
IMG_0531
PICT0009
IMG_0416
RAY HASSMAN GROUP 015
P_5

then my output is

P_5 HASSMAN GROUP 015

Why am I getting this weird mess?

As asked here is the hex dump of my input file

0000: 50 5F 34 0D 49 4D 47 5F   P_4¬IMG_
0008: 30 35 33 31 0D 50 49 43   0531¬PIC
0010: 54 30 30 30 39 0D 49 4D   T0009¬IM
0018: 47 5F 30 34 31 36 0D 52   G_0416¬R
0020: 41 59 20 48 41 53 53 4D   AY HASSM
0028: 41 4E 20 47 52 4F 55 50   AN GROUP
0030: 20 30 31 35 0D 50 5F 35    015¬P_5

I am using Mac 10.9.2 build 13c39

traisjames
  • 140
  • 8

1 Answers1

0

Instead of line ending characters, your script produces "\r" characters that move the cursor to the leftmost position, but do not advance a line. Therefore, all the information is overwriting itself over and over. I cannot imagine how this can happen with literal "\n" in the code - are you sure the code you posted produces the output? What OS are you on? Can you post a hexdump of the input file?

choroba
  • 19,261
  • 4
  • 49
  • 52