Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > dump the content of a string

Reply
Thread Tools

dump the content of a string

 
 
toylet
Guest
Posts: n/a
 
      02-25-2004

my $line=<>;

I input 'a' and press enter.

$line should now be 2 bytes in length.

1. How could I access the 2 bytes respectively
2. and print them in hex format?

--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 9:04pm up 2:47 1 user 1.12 1.04
 
Reply With Quote
 
 
 
 
Web Surfer
Guest
Posts: n/a
 
      02-25-2004
[This followup was posted to comp.lang.perl.misc]

In article <403c9dd8$(E-Mail Removed)-cable.com>, toylet
<toylet_at_mail.hongkong.com> says...
>
> my $line=<>;
>
> I input 'a' and press enter.
>
> $line should now be 2 bytes in length.
>
> 1. How could I access the 2 bytes respectively


You can use "substr" to extract portions of strings


> 2. and print them in hex format?



printf "%02x\n",$data; # print data in hex
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-25-2004
toylet wrote:
> my $line=<>;
>
> I input 'a' and press enter.
>
> $line should now be 2 bytes in length.


Not necessarily. It depends on your OS.
If you want to write portable code don't expect the input to be just 2
characters.

> 1. How could I access the 2 bytes respectively


perldoc -f substr

> 2. and print them in hex format?


perldoc -f ord
perldoc -f hex

jue


 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      02-25-2004
>>>>> "JE" == Jürgen Exner <(E-Mail Removed)> writes:

>> 2. and print them in hex format?


JE> perldoc -f ord
JE> perldoc -f hex

hex converts from ascii hex to binary. it doesn't print hex.

sprintf or unpack are two ways to do it.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dump complete java VM state as core dump (not via OS) possible? halfdog Java 12 02-21-2013 06:14 AM
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
string byte dump Jammer Python 3 01-28-2007 09:32 PM
JNI FindClass(java/lang/string) causes core dump on AIX 5.2 abhijit.dhariya@gmail.com Java 2 03-31-2006 08:00 PM
string ok as public causes core dump as public Jake C++ 1 11-11-2005 01:04 PM



Advertisments