아래와 같은 포맷의 hexadecimal로 이루어진 input 파일을 받아 binary mode output file을 생성하는 perl script
[Input]
a1
b3
23
14
...
[Perl script]
#!/usr/bin/perl
use strict;
my $input_file;
my $output_file;
my $line;
my $tmp;
print("====================\n");
print("Hex to Bin Converter\n");
print("====================\n");
open(INFILE, $ARGV[0]) || die("Cannot open input file\n");
$input_file = $ARGV[0];
$output_file = $ARGV[1];
print("Input filename: ${input_file}\n");
print("Output filename: ${output_file}\n");
print("\n");
open(OUTFILE, ">${output_file}");
binmode OUTFILE;
while($line=<INFILE>) {
chomp($line);
$tmp = chr(hex($line));
print(OUTFILE "${tmp}");
}
close(INFILE);
[Usage]
./hex2bin input_filename output_filename
'Linux' 카테고리의 다른 글
[vi] 편리한 몇가지 팁 (0) | 2011.02.17 |
---|---|
[Perl] Bin to Hex Converter (0) | 2011.02.14 |
[vi] Folding (0) | 2011.02.08 |
[Perl] File I/O (0) | 2011.01.05 |
[C shell] C shell에서 각 명령어의 return value 사용 ($status) (0) | 2010.11.25 |