468,316 Members | 2,053 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Help reg printing non printable hex characters

Hi All,

i am trying to write a code which will take a non printable character as an input and used as a separator for different fields

ex : if user gives an input \xd1 the o/p should be field1 ╤ field2

initially i have written a code to get the below lines in my program hex.pl

Expand|Select|Wrap|Line Numbers
  1.  
  2. use strict;
  3.  
  4. my $seperatorArg;
  5.  
  6. $seperatorArg = shift(@ARGV);
  7.  
  8. print "field1 $seperatorArg field2";
  9.  
  10.  
when i ran "perl hex.pl \xd1" i got the below o/p

field1 \xd1 field2

if i hardcode the value in my code like
Expand|Select|Wrap|Line Numbers
  1. $seperatorArg = "\xd1";
  2.  
i am getting the desired.

can anybody explain my below understanding is correct?

what i am thinking is when i hard code, the value i gave in double quotes and hence the variable interpoplation is occuring which results in hex character

when i gave the same value as input in command line the value is getting in single quotes which is not getting interpolated and hence the same value is being printed.

please point me to the right direction if i am in wrong direction, so tht i can put more effort to make my code to behave in the way i want.

Thanks
Raj
Jun 17 '08 #1
3 1799
KevinADC
4,059 Expert 2GB
Hi All,

i am trying to write a code which will take a non printable character as an input and used as a separator for different fields

ex : if user gives an input \xd1 the o/p should be field1 ╤ field2

initially i have written a code to get the below lines in my program hex.pl

Expand|Select|Wrap|Line Numbers
  1.  
  2. use strict;
  3.  
  4. my $seperatorArg;
  5.  
  6. $seperatorArg = shift(@ARGV);
  7.  
  8. print "field1 $seperatorArg field2";
  9.  
  10.  
when i ran "perl hex.pl \xd1" i got the below o/p

field1 \xd1 field2

if i hardcode the value in my code like
Expand|Select|Wrap|Line Numbers
  1. $seperatorArg = "\xd1";
  2.  
i am getting the desired.

can anybody explain my below understanding is correct?

what i am thinking is when i hard code, the value i gave in double quotes and hence the variable interpoplation is occuring which results in hex character

when i gave the same value as input in command line the value is getting in single quotes which is not getting interpolated and hence the same value is being printed.

please point me to the right direction if i am in wrong direction, so tht i can put more effort to make my code to behave in the way i want.

Thanks
Raj
You seem to have determined what the problem is. \x is not getting interpolated. Unfortunately I don't know how you can accomplish what you want. Probably pack/unpack/sprintf but I don't know how. Ask on www.perlmonks.com if you don't get an answer here.
Jun 17 '08 #2
Hi Kevin

Thanks for your pointers

i tried in this way

Expand|Select|Wrap|Line Numbers
  1. use constant HEXD1 => "\xd1";
  2. use constant HEXDC => "\xdc";
  3.  
  4.  
  5. $arg = shift(@ARGV);
  6.  
  7. if ($arg eq "HEXD1") {
  8.     $arg = HEXD1;
  9.     print " HEX D1 IS $arg \n";
  10. }
  11. elsif ($arg eq "HEXDC") {
  12.                 $arg = HEXDC;
  13.     print " HEX DC IS $arg \n";
  14. }
  15.  
i am running the program as below

perl hex.pl HEXD1

perl hex.pl HEXDC

i know this is a bad way of coding.... :(

trying in different ways.. but couldnt get the expected o/p.

may i get any other pointers

-Raj
Jun 18 '08 #3
KevinADC
4,059 Expert 2GB
A hash would easier to use but I think if you ask on perlmonks someone there will give you a good suggestion.
Jun 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Pascal | last post: by
9 posts views Thread by Pemburger | last post: by
3 posts views Thread by Russell McDade | last post: by
2 posts views Thread by PC User | last post: by
25 posts views Thread by mdh | last post: by
14 posts views Thread by abhishekkarnik | last post: by
8 posts views Thread by Frank Rizzo | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.