Joel wrote:
>
> I'm trying to write a program in perl that will take a binary file, convert
> it to hex, then save it to a text file. So far I'm not having any luck. The
> best I've been able to do is copy the file and open it in a text editor.
> Here is my code:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> print "Enter path:\n";
> my $filename = <>;
> chomp $filename;
> print "Save as what?\n";
> my $savefile=<>;
> chomp $savefile;
> open (BINARY, "$filename") || die "Couldn't open file: $!";
> binmode BINARY;
> my $x=BINARY;
> open (SAVE,">$savefile") || die "Unable to save: $!";
> print SAVE 0b"$x";
> close BINARY;
> close SAVE;
>
> Any ideas?
Perhaps this is what you want:
#!/usr/bin/perl
use warnings;
use strict;
print 'Enter path: ';
chomp( my $filename = <STDIN> );
print 'Save as what? ';
chomp( my $savefile = <STDIN> );
open BINARY, '<', $filename or die "Couldn't open file: $!";
binmode BINARY;
open SAVE, '>', $savefile or die "Unable to save: $!";
while ( <BINARY> ) {
print SAVE unpack( 'H*', $_ ), "\n";
}
close BINARY;
close SAVE;
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>