Stephane CHAZELAS wrote:
I actually meant that "^@^X^@^A^@^AA" was actually the character
0x00 followed by the character 0x18... Such characters can't be
included in newsgroup messages, neither can't they generally be
seen, hence the need of a representations such as ^@, ^X.
But they can if they are part of the actual code - which is what the OP
posted ... not a representation of what he wanted, but the actual code
AFAIK. If the OP says I'm wrong, so be it.
[...]
... which isn't what the OP wanted
To complicate things, he appears to be using EBCDIC, not ASCII values as
the final result. '41' is 'A' in ASCII, but in EBCDIC it's represented by
'C1'. And, in your solution, you don't appear to take into account that
'^' is a control character (much like the infamous '^M' you get when
getting a DOS file and placing it in binary format on a Unix box).
[...]
I took it into account, that's what I explained. ^X (aka Ctrl-X)
is the character 0x18. I assumed the ^X in OP's message was
actually the representation of the 0x18 character.
The OP was very clear about what he wanted to see.
You're right however about the EBCDIC issue.
The OP, however, was not clear about this.
However if his system charset is EBCDIC (which the fact that he
said that the result should be the hex representation suggests),
my code would still work (pack("H*", "A") would return "C1").
$ cat -vt input-file
01 SYSOT VALUE '^@^X^@^A^@^AA' PIC X(07)
$ od -tc input-file
0000000 0 1 S Y S O T V A L
0000020 U E ' \0 030 \0 001 \0 001 A '
0000040 P I C X ( 0 7 ) \n
0000057
$ cat perl-script
s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e
~$ perl -p perl-script input-file
01 SYSOT VALUE X'00180001000141' PIC X(07)
What OS are you running? Because I did the following and got different
results. The OS I'm running is Linux (Fedora Core 2 and Red Hat 8.0 -
not sure about the kernel version on the Fedora box, but it's using
5.8.3 Perl - since I'm at work right now, but the Red Hat box is
running a 2.4.18 kernel and 5.8.0 Perl).
This is what I got duplicating your commands and files ...
[jim@oplinux tmp]$ cat -vt input-file
01 SYSOT VALUE '^@^X^@^A^@^AA' PIC X(07)
[jim@oplinux tmp]$ od -tc input-file
0000000 0 1 S Y S O T V A L
0000020 U E ' ^ @ ^ X ^ @ ^ A ^ @ ^ A
0000040 A ' P I C X
0000060 ( 0 7 ) \n
0000065
[jim@oplinux tmp]$ cat perl-script
s/VALUE '(.*?)'/"VALUE X'" . unpack("H*", $1) . "'"/e
[jim@oplinux tmp]$ perl -p perl-script input-file
01 SYSOT VALUE X'5e405e585e405e415e405e4141' PIC X(07)
[jim@oplinux tmp]$
This is starting to bug me that I got different results and executed
the *same* commands. I realize that the various characters, when
*printed* will vary, but the OP provided *code* that *should* print.
And the commands you execute *should* yield the *same* results ... and
it's not.
So ... what am I doing differently from you that produces different
results? I'm sure the OP might be interested as well ... if he's still
with us and following along and is getting what I'm getting.
Jim