#!/usr/bin/perl; use strict; use warnings; # ! / u s r / b i n / my $buf = pack ('C*', (0x23, 0x21, 0x2F, 0x75, 0x73, 0x72, 0x2f, 0x62, 0x69, 0x6E, 0x2f)); # $buf is now a sequence of "characters" which are 8 bit unsigned numbers # Don't go all crazy with me about multi-byte characters # Here "C" means 8 bits, one byte # The ASCII characters corresponding to those numbers are: # #!/usr/bin/ # to get a particular characters or a group of characters # from the $buf string, use substr() # # substr EXPR,OFFSET,LENGTH,REPLACEMENT # substr() is often used in conjection with unpack to generate # a particular numeric value with different byte ordering of say # a 16 or 32 or 64 bit value print substr($buf,3,3); #prints: usr print "\n"; print substr($buf,7,4); #prints: bin/ print "\n"; # Now translate each byte in $buf into an array.. # Each 8 bit character will be a represented on my # computer as a 64 bit signed value in an array of # what are named "bytes" my @bytes = unpack ('C*',$buf); # @bytes is now an array of numbers! # in decimal values: print "Decimal Values of \@bytes\n"; print "$_ " for @bytes; print "\n"; # Now to print those bytes in character context: print "Character values of \@bytes\n"; print chr($_) for @bytes; print "\n"; __END__ usr bin/ Decimal Values of @bytes 35 33 47 117 115 114 47 98 105 110 47 Character values of @bytes #!/usr/bin/