Perl Basics
Introduction to Perl
FAQ's
CGI
Regular Expressions

PC Overview
Cool Stuff
My Modules
Success Stories
Links
Perl in the News
Logos

PC Internals
About
Contact
Handy Logos
What's new

ISO2Hex

Useful as /usr/local/bin/iso2hex
See also
P-friendly

[ home ] - [ search ] - [ sitemap ]


#!/usr/bin/perl -w
 
# Usage:

# ./iso2hex.pl < input
 
use strict;
 
&main();
 
sub main() {
        while (<>) {
                chomp;
                my $hex = &iso2hex($_); $hex =~ tr/ //d;
                print $hex, "\n";
        }
}
 
sub iso2hex($) {
        my $hex = '';
        for (my $i = 0; $i < length($_[0]); $i++) {
                my $ordno = ord substr($_[0], $i, 1);
                my $hx = sprintf("%lx ", $ordno);
                   $hx = "0$hx" if length($hx) < 3;
                $hex .= $hx;
        }
 
        $hex =~ s/ $//;
        $hex;
}
home - feedback - search

$Id: foo.htm,v 1.10 2004/03/11 17:50:01 reto Exp $
© 1998-2004 reto :)