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 ¨h field2 initially i have written a code to get the below lines in my program hex.pl
use strict; my $seperatorArg; $seperatorArg = shift(@ARGV); print "field1 $seperatorArg field2";
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
$seperatorArg = "\xd1";
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 another way i tried is
use constant HEXD1 => "\xd1"; use constant HEXDC => "\xdc"; $arg = shift(@ARGV); if ($arg eq "HEXD1") { $arg = HEXD1; print " HEX D1 IS $arg \n"; } elsif ($arg eq "HEXDC") { $arg = HEXDC; print " HEX DC IS $arg \n"; }
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. Kindly provide me the pointers on this.

In reply to Help reg printing non printable hex characters by user1357

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.