#!/usr/local/bin/perl ########################## ### precat.pl ### "precat.pl" converts any file into perl-script. ### The converted-script outs same of the file into STDOUT. ### ### "precat.pl" effects as "cat" command on UN*X, ### but file read occurs when convert. ### I tested it at "perl, v5.6.0 built for MSWin32-x86-multi-thread". ### ### "precat.pl" coded by NAKATA Yoshinori (white@mh.vis.ne.jp) ### You can use it with no-restriction. ### But I want you keep this comment if you re-distribute it. ### ## for nice look of converted-script. $COLUMNS = 60; ## Argument Check if(scalar(@ARGV) != 1){ print STDERR "Usage: perl $0 input_file\n"; exit(0); } ## read file & convert into perl-code. open(FILE, $ARGV[0]); while(!eof(FILE)){ $char = getc(FILE); $c = ord($char); if($char =~ /[0-9a-zA-Z]/){ $result .= $char; }else{ $a = $c % 8;$c = int($c / 8); $b = $c % 8;$c = int($c / 8); $result .= "\\".$c.$b.$a; } if(length($result) > $COLUMNS){ push(@result,$result); undef($result); } } push(@result,$result); ## output perl-script. print 'binmode STDOUT;'."\n"; foreach(@result){ print '$bin .= "'.$_.'";'."\n"; } print 'print $bin;'."\n"; exit(0);