On Thu, Oct 28, 2010 at 07:28:19PM +0530, perl_haxor 123 wrote:
> characters and how can remove them using perl?.....and also please let me if
> there is any link form where i can find what these characters are and their
> ascii values?......any sugges would be really helpful

# man ascii

If that fails:
<code>
#!/usr/bin/perl -Tw
#   ascii Thu Dec 11 2008 (c) Mike McClain
#   print ascii chart, oct, hex, dec ala, /mc/docs/ascii.gz
#   re: man ascii

use strict;     #   this can be removed when all bugs are fixed
use warnings;   #   duplicates -w
use integer;
$|++;           #   unbuffered STDOUT

#   requires explicit package name
my ($hi_ascii, $do_oct, $do_hex, $do_dec, $do_ctrl) = (0,0,0,0,0);

##  get CL switches
$hi_ascii = 1                           if( @ARGV && ($ARGV[0] =~ /h/i) );
$do_oct   = 1                           if( @ARGV && ($ARGV[0] =~ /o/i) );
$do_hex   = 1                           if( @ARGV && ($ARGV[0] =~ /x/i) );
$do_dec   = 1                           if( @ARGV && ($ARGV[0] =~ /d/i) );
$do_ctrl  = 1                           if( @ARGV && ($ARGV[0] =~ /c/i) );

my $sep = '|';
my @symbols = qw/
    nul soh stx etx eot enq ack bel
    bs  ht  nl  vt  np  cr  so  si
    dle dc1 dc2 dc3 dc4 nak syn etb
    can em  sub esc fs  gs  rs  us
    sp  del/;

my $control_chars = q{    Control Characters
     0 Ctrl @  NUL '\0'                    16 Ctrl P  DLE (data link escape)
     1 Ctrl A  SOH (start of heading)      17 Ctrl Q  DC1 (device control 1)
     2 Ctrl B  STX (start of text)         18 Ctrl R  DC2 (device control 2)
     3 Ctrl C  ETX (end of text)           19 Ctrl S  DC3 (device control 3)
     4 Ctrl D  EOT (end of transmission)   20 Ctrl T  DC4 (device control 4)
     5 Ctrl E  ENQ (enquiry)               21 Ctrl U  NAK (negative ack.)
     6 Ctrl F  ACK (acknowledge)           22 Ctrl V  SYN (synchronous idle)
     7 Ctrl G  BEL '\a' (bell)             23 Ctrl W  ETB (end of trans. blk)
     8 Ctrl H  BS  '\b' (backspace)        24 Ctrl X  CAN (cancel)
     9 Ctrl I  HT  '\t' (horizontal tab)   25 Ctrl Y  EM  (end of medium)
    10 Ctrl J  LF  '\n' (line feed)        26 Ctrl Z  SUB (substitute)
    11 Ctrl K  VT  '\v' (vertical tab)     27 Ctrl [  ESC (escape)
    12 Ctrl L  FF  '\f' (form feed)        28 Ctrl /  FS  (file separator)
    13 Ctrl M  CR  '\r' (carriage ret)     29 Ctrl ]  GS  (group separator)
    14 Ctrl N  SO  (shift out)             30 Ctrl ^  RS  (record separator)
    15 Ctrl O  SI  (shift in)              31 Ctrl -  US  (unit separator)
};

if( $do_oct || $do_hex || $do_dec || $do_ctrl )
{   if($do_ctrl)
    {   print "$control_chars\n";
    }
    if($do_oct)
    {   print "octal table\n";
        print_ascii('o', $hi_ascii);
        print "\n";
    }
    if($do_hex)
    {
        print "hex table\n";
        print_ascii('x', $hi_ascii);
        print "\n";
    }
    if($do_dec)
    {   print "decimal table\n";
        print_ascii('d', $hi_ascii);
        print "\n";
    }
}
else
{   print "\n$control_chars\n";
    print "octal table\n";
    print_ascii('o', $hi_ascii);
    print "\n";
    print "hex table\n";
    print_ascii('x', $hi_ascii);
    print "\n";
    print "decimal table\n";
    print_ascii('d', $hi_ascii);
}

#   -------     end of main     -------------------
sub print_ascii
{   my ($mode, $hi) = @_;
    $mode =~ /^[dox]$/          || die "Unknown mode in print_ascii($mode) \n";
    $mode = ( $mode =~ /d/) ? '%3d' : ( $mode =~ /x/) ? ' %02x' : '%03o';
    unless($hi)
    {   for my $i ( 0 .. 127)
        {   if( $i < 33)
            {   printf( "$sep$mode %-3s", $i, $symbols[$i]); }
            elsif( $i == 127)
            {   printf( "$sep$mode del", $i ); }
            else
            {   printf( "$sep$mode  %s ", $i, chr($i) ); }
            ( (($i + 1) % 8) == 0) && print "|\n";
        }
    }
    else
    {   for my $i ( 128 .. 255)
        {   printf( "|$mode  %s ", $i, chr($i) ); 
            ( (($i + 1) % 8) == 0) && print "|\n";
        }
    }
}
__END__
</code>
-- 
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to