"fhscobey" <> wrote in
news: ps.com:
> Hi,
> Just curious if anyone knows why the following happens:
>
> Example 1:
> $ perl -e 'print("\x{4A}\x{65}\x{66}\x{66}","\n");'
> Jeff
>
> Example 2:
> $ echo '\x{4A}\x{65}\x{66}\x{66}' | perl -e
> 'while(<STDIN>){print("$_");}'
> \x{4A}\x{65}\x{66}\x{66}
>
> Example 3:
> $ echo '\x{4A}\x{65}\x{66}\x{66}' | perl -e
> 'while(<STDIN>){$line="$_"; chomp($line); @chars=split(//,"$line");
> foreach $ch (@chars){print($ch,"|");}}'
> \|x|{|4|A|}|\|x|{|6|5|}|\|x|{|6|6|}|\|x|{|6|6|}|
>
> Not sure why Perl doesn't recognize the string in Ex. 2 as a hex
> string. Anyone know why?
From perldoc perlop:
The following escape sequences are available in constructs that
interpolate and in transliterations.
\t tab (HT, TAB)
\n newline (NL)
\r return (CR)
\f form feed (FF)
\b backspace (BS)
\a alarm (bell) (BEL)
\e escape (ESC)
\033 octal char (ESC)
\x1b hex char (ESC)
\x{263a} wide hex char (SMILEY)
\c[ control char (ESC)
\N{name} named Unicode character
A double-quoted string in program source interpolates. Input does not.
You can interpret the escape sequences yourself:
#!/usr/bin/perl
use strict;
use warnings;
while (my $line = <STDIN>) {
my $str;
while ($line =~ m/ \\x{([[

digit:]]+)} /xg) {
$str .= chr(hex $1);
}
print "$str\n";
}
__END__
D:\Home\asu1\UseNet\clpmisc> bug
\x{73}\x{69}\x{6e}\x{61}\x{6e}
sinan
Or:
#!/usr/bin/perl
use strict;
use warnings;
while (my $line = <DATA>) {
$line =~ s/ \\x{([[

digit:]]+)} / chr(hex $1) /xge;
print $line;
}
__DATA__
\x{53}\x{69}\x{6e}\x{61}\x{6e}
--
A. Sinan Unur <>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html