 |
|
 |
|
Views: 235,871,251 Time: 2013-05-19 09:26:51 AM | 7 users online: brunochicoria, Donaldthescotishtwin, DragezeeY, exit1337, iRhyiku, Ludus, Ragey - Guests: 24 - Bots: 13 | Users: 22,840 (1,288 active) Latest: neagix |
|
|
 |
|
 |
|
| Tip: Don't place Yoshi coins near a goal post because they keep glowing when a level fades out. |
|
|
|
 |
|
 |
|
 |
|
 |
|
| Help with Perl |
|
Forum Index - Hobbies - Computers & Technology - Help with Perl |
|
Pages: 1  |
|
|
|
| Posted on 2010-11-21 10:03:52 PM |
Link | Quote |
|
|
I've been messing around with Perl lately, reading in text files, writing to binary files, and the like, and I'm getting a very odd bug when converting numeric values to ASCII characters. Whenever I try to print character 10, 0r 0x0A, the program always also prints character 13, or 0x0D, before it. The bug seems to happen with that one character and that one character only; every one of the other 255 character values works correctly. Does anyone know what causes this or how to fix it?
|
| Last edited on 2010-12-30 07:45:19 PM by imamelia. |
|
| Posted on 2010-11-21 10:13:37 PM |
Link | Quote |
|
In Windows, newlines are \r\n, or chr(10).chr(13). Perl automatically adds the \n symbol to make the file in DOS format and be readable in programs such as Notepad. So, it's not a bug, but it's more of a feature.
I think.
|
|
| Posted on 2010-11-21 11:56:21 PM |
Link | Quote |
|
|
I know in Python that that will happen in windows if you don't open the file for writing in binary mode, not entirely sure how it works in perl, but if there is a similar binary read/write mode, try using that.
|
|
| Posted on 2010-11-24 11:22:49 PM |
Link | Quote |
|
Oh, I see. Huh...I thought I was in binary mode there, but I guess I forgot anyway. Odd.
Well, that clears that up...may I use this thread for future questions about Perl?
|
|
| Posted on 2010-12-30 04:34:02 PM |
Link | Quote |
|
Okay, new problem. I'm using the mkdir function to create a new subfolder for some files, and it works fine...unless the folder is already there, in which case, I get an error. What can I do to make it create the folder only if it isn't there already, and if it is, just use the existing one?
Edit: Never mind, solved.
|
| Last edited on 2010-12-30 07:44:59 PM by imamelia. |
|
| Posted on 2010-12-31 04:25:12 PM |
Link | Quote |
|
Aaand just in case someone else has the same problem:
Code$path = "C:/Path/to/whatever";
mkdir $path if(!-d $path);
|
|
| Posted on 2011-02-05 12:49:45 AM |
Link | Quote |
|
I'm having trouble reading in data from a binary file. I have this code:
Code #$i = 0;
#$TileData = 0x0000;
$GFXFileBits = ((($GFXFileBits >> 8) & 0x00FF) | (($GFXFileBits << 8) & 0xFF00));
#printf "%04X","$GFXFileBits";
#print $GFXFileBits;
while(!(eof(IN)))
{
$BytesRead = read(IN, $TileData, 2);
unless($BytesRead != 2)
{
#$NewTileData = (($TileData & 0xFC7F) | ($GFXFileBits));
$NewTileData = (($TileData & 0x7FFC) | ($GFXFileBits));
print OUT $NewTileData;
next;
}
}
My intention is to read 2 bytes at a time from a .bin file, clear specific bits of them, add in bits from a variable, and output the result into a new .bin file. It's supposed to do this until all data has been read from the first file and written to the second. I can't figure out the best way to do this, though...the method I'm using in that code is unquestionably not working. My only Perl programming book doesn't explain the read() function well at all, either. (And for some reason, the printf function always prints 0000.)
|
|
|
Pages: 1  |
|
|
|
|
Forum Index - Hobbies - Computers & Technology - Help with Perl |
|
|
 |
|
 |
The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.
Copyright © 2005 - 2013 - SMW Central Legal Information - Link To UsTotal queries: 27
|
|
|
|