|
发表于 2015-4-7 19:17:00
|
显示全部楼层
#!perl -w
#
# Usage: convert.pl [source file] [destination file]
# If we donot provide source file, STDIN will be used as source.
# If we donot provide destination file, a file named a.out will be used as output.
if ($#ARGV != 1)
{
print "Use a.out as default output file.\n";
$destfile = "a.out";
}
else
{
$destfile = $ARGV[1]; #using user defined output file
}
open OUTF, ">$destfile" or die "Can't open $destfile for writing!\n";
binmode(OUTF);
while (<>)
{
for $chunk (split(/ /, $_))
{
print OUTF pack("H2", $chunk); #use pack function to write data in binary format
}
}
close(OUTF); |
|