Thomas Thomas - 7 months ago 13
Perl Question

Concatenation overwrites string and is mixed up

I've recently wrote a converter, which takes our old wiki pages and converts them into SharePoint Pages.
All this was done via command line, but now I switched to GUI with Win32.

I'm still new to perl and just copied my working code to my with fancy GUI things.

Everything works expect this line:

$newFileName = 'Pages/'.$file.'.aspx';

It should output a path to my directory (Pages/TheFileName.aspx) where I store the converted pages.
However I get this when I print $newFileName:


.aspx overwrites Pages instead of a concat at the end.
Now I've tried hundreds of other combinations but the second concatenation just overwrites my text?!

It's the exact same line, which is working in my other script.
I bet its just a novice mistake, but I can't figure it out...

Thanks in advance for your help!


Exact content of $newFileName seems to be


which, when printed out looks like


because included "\r" (carriage return) causes cursor to go to start of the line so that ".aspx" overwrites "Pages" on screen.

So simple fix (as already mentioned in comments) is to remove "\r" from $file, e.g. with

$file =~ s/\r//g;

Problems like this can be quite common in Windows because in Windows newline is "\r\n" while many unix-like programs except "\n", so it's easy to have that extra "\r" left in strings.