Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options


by turnstep (Parson)
on Aug 08, 2000 at 23:57 UTC ( #26874=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts/Text Processing
Author/Contact Info turnstep

Just a simple hex editor-type program. I actually wrote this back in 1996, so go easy on it! :) I cleaned it up a little to make it strict-compliant, but other than that, it is pretty much the same. I used it a lot when I was learning about how gif files are contructed. Good for looking at files byte by byte.

I have no idea why it was named wanka but it has stuck. :)

#!/usr/bin/perl -- -*-fundamental-*-

## Note: written in 1996 so I am not sure why I use 
## "BRASS" and "gold". It may have been because I was 
## playing with POV-RAY...

use strict;

my $gzcat = "/usr/local/bin/gzcat";
my $file;

unless ($file = shift) {
  print "What file? ";
  chop($file = <STDIN>);

my $cols = shift;
if ($cols<1 or $cols > 20) { $cols=12; }

my $oneline = shift;

if ($file =~ /\.gz$/) {
  open(GOLD, "$gzcat $file|") || die qq[Sorry, can't open "$file": $!\
else {
  open(GOLD, $file) || die qq[Sorry, can't open "$file": $!\n];

print "\n$file:\n";
my $x=0; my $line=0; my $chars=0; my $page=1; my $totalchars=0;
my $brass; my $newline; my $fin; my $all;
while (read(GOLD, $brass, 1)){
  if ($fin) { print "    "; $brass=''; }
  else { printf "%3d ", ord($brass); }

  if ($oneline and ord($brass)==10) { $fin=1; }
  $totalchars++; $chars++;
  $all .= $brass;
  if ($x++ > $cols) {
    print "  ";
    if ($all =~ y/\n/$/) { $newline=1; }
    $all =~ y/\t/=/;
    $all =~ y/\0-\37\177-\377/?/;
    print "$all\n";
    $all = "";
    if ($line++ > $LINESPERPAGE) {
      print " ($totalchars characters) (Page: $page)";
      print "  <<HIT RETURN FOR MORE>> ";
      $a = <STDIN>;
      if ($page++ > 1 and $a =~ /-/) {
        seek(GOLD, -$chars*2, 1); $totalchars-=$chars*2;
      print "\n";
$newline and $oneline and exit;

## Clean up any extra:
$all =~ y/\0-\37\177-\377/./;
for ($x..$cols) { print "****"; }
print "***    $all\n\n";
print "($totalchars characters)\n";

print "\n\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://26874]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-10-27 13:56 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (256 votes). Check out past polls.