473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1983
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

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

Similar topics

3
by: Pascal | last post by:
Hello, What's the best way to delete or replace no-printable characters in a string. i.e.: "\x08toto\x00titi" -> "tototiti" or " toto titi"
9
by: Pemburger | last post by:
From: pemburger@aol.com I've tried the W3C MarkUp Validation Service for the following web page: http://www.coverscript.com The report given by W3C shows 300 plus errors? I am not able to...
3
by: Russell McDade | last post by:
I have a html page that I don't want anyone to print. Is there a way using JavaScript to send an alert to the user to warn them from trying to print the html page? Is there an onPrint event...
2
by: PC User | last post by:
I found some VB code to printout a richtext field and I'm trying to adapt it to MS Access 2000. I think there might be some small changes to make the adaption between VB versions. Also my OS is...
25
by: mdh | last post by:
I wrote a little insignificant program, to help me write a more significant one!!...that was supposed to print all Ascii values from 0 to 127: >>>> #include <stdio.h> # define UPPER_LIMT 127...
7
by: active | last post by:
I want to remove all non-printable characters - including nulls. I could extend the following by adding as many printable characters as I can think of. But I wonder if there isn't something...
14
by: abhishekkarnik | last post by:
Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I...
8
by: Frank Rizzo | last post by:
I am trying to print huge images (much bigger than target paper). I try and use e.PageSettings.HardMarginX and e.PageSettings.HardMarginY in the PrintDocument's PrintPage event to try and...
1
by: daschicken | last post by:
Hi guys, currently I'm encountering a strange behavior while using the PrinterJob class. I've got a little program printing some pages. Most of the time the printer does its job as it should....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.