Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

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


then my output is


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

share|improve this question
Is there any tab character in the file? Also, you chomp $_, but do not use it afterwards. –  choroba Jan 18 '14 at 21:38
whoops using an old version of the code. just updated it. Still get P_5 HASSMAN GROUP 015 –  traisjames Jan 18 '14 at 23:13

1 Answer 1

up vote 0 down vote accepted

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?

share|improve this answer
Ok I added the dump to my OP –  traisjames Jan 20 '14 at 0:32
Yes, it is as I guessed. If you print "a\x0db", Perl will print a, return back left and overwrite the a with b. –  choroba Jan 20 '14 at 1:37
ok so I should go into the list file using a regex program (text wrangler) and do a s#\r#\n#g ? –  traisjames Jan 29 '14 at 0:39
@traisjames: Try that. You can use Perl to change the file, BTW. –  choroba Jan 29 '14 at 9:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.