in reply to Re: Help reg printing non printable hex characters
in thread Help reg printing non printable hex characters

# in the code my $arg = hex(shift @ARGV);

Wouldn't that rather be

my $arg = chr hex(shift @ARGV);

(hex gives a number (e.g. 209 for "d1"), but it seems the OP actually wants the respective char, i.e. chr(209)... )

BTW, another possibility would be

my $sep = pack "H2", (shift @ARGV); # with input being 'd1', for exam +ple

Or, if you insist on specifying the \x prefix on input, you could extract the hex part with a regex

my $sepArg = shift @ARGV; my ($hex) = $sepArg =~ /\\x([\da-fA-F]+)/; my $sep = chr hex $hex; my $str = "field1 $sep field2";

Update: in theory, you could also do

my $sepArg = shift @ARGV; # input being '\xd1', for example my $str = eval qq("field1 $sepArg field2");

but don't do that if your user input comes from untrusted sources... (any code could be executed!)

Replies are listed 'Best First'.
Re^3: Help reg printing non printable hex characters
by user1357 (Initiate) on Jun 18, 2008 at 14:02 UTC
    Hi All, Thanks a lot for support and guidance. my original requirement is to get the data from an oracle table and prepare an extract with the configured column and line seperators. input is configuration purpose only. anyways i will avoid the spl characters. once again Thanks a lot.