choedebeck has asked for the wisdom of the Perl Monks concerning the following question:
But I am having trouble taking this hex representation and recreating the binary file with it. Here is the script I have currently that is not workingmy $buffer; open INFILE, "test.bin" or die "Can't open test.bin for reading: $!\n" +; open OUTFILE, ">test.bin" or die "Can't open test.bin for writing: $!\ +n"; select OUTFILE; binmode INFILE; while (read(INFILE, $buffer, 1) and printf("%X", ord($buffer))){}; print "\n";
This code just write a bunch of number to the binary file which is not what I want. Anyone have any ideas on what I am doing wrong?my $buffer; open INFILE, "test.text" or die "Can't open test.txt for reading: $!\n +"; open OUTFILE, ">test_updated.bin" or die "Can't open test_updated.bin +for writing: $!\n"; binmode OUTFILE; my $line = <INFILE>; chomp $line; my @list = split //, $line; my $hex_value; my $i =1; foreach my $character (@list) { if($i%2 == 0) { $hex_value .= $character; syswrite OUTFILE, hex($hex_value); } elsif($i%2 == 1) { $hex_value = "0x".$character; } $i++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recreating a binary file from hex representation
by davido (Cardinal) on Jul 07, 2006 at 16:05 UTC | |
|
Re: Recreating a binary file from hex representation
by shmem (Chancellor) on Jul 07, 2006 at 17:42 UTC | |
|
Re: Recreating a binary file from hex representation
by planetscape (Chancellor) on Jul 07, 2006 at 17:40 UTC | |
|
Re: Recreating a binary file from hex representation
by wazoox (Prior) on Jul 07, 2006 at 21:46 UTC | |
|
Re: Recreating a binary file from hex representation
by TedPride (Priest) on Jul 07, 2006 at 16:10 UTC |