[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] escape oddities...




Chris Nandor wrote to Scott Prince:

> \cM means carriage return, \cJ means linefeed.  There is no list of every
> possible sequence, really, unless you have a list of all octal and hex
> sequences.  And Unicode is around the corner, which adds more.

There are indeed such lists: they are usually called ASCII tables.

    chr(65) eq 'A'
    chr(65 ^ 64) eq chr(1)
    chr(65 ^ 64) eq "\cA"

and so on. Qua script:

#!/perl
 $c[0]="\cA";  $c[1]="\cB";  $c[2]="\cC";  $c[3]="\cD";  $c[4]="\cE"; 
 $c[5]="\cF";  $c[6]="\cG";  $c[7]="\cH";  $c[8]="\cI";  $c[9]="\cJ"; 
$c[10]="\cK"; $c[11]="\cL"; $c[12]="\cM"; $c[13]="\cN"; $c[14]="\cO"; 
$c[15]="\cP"; $c[16]="\cQ"; $c[17]="\cR"; $c[18]="\cS"; $c[19]="\cT"; 
$c[20]="\cU"; $c[21]="\cV"; $c[22]="\cW"; $c[23]="\cX"; $c[24]="\cY"; 
$c[25]="\cZ"; 
for (65..65+25) {
    $c=chr($_); 
    $b = $c[$_ - 65];
    printf "%d, %s %s %s\n", $_, $c, 
             (chr($_ ^ 64) eq chr($_ - 64)) ? 'yes' : 'no',
             (chr($_ ^ 64) eq $b) ? 'yes' : 'no';
}

__END__

Which prints out:

65, A yes yes
66, B yes yes
67, C yes yes
[snip]
88, X yes yes
89, Y yes yes
90, Z yes yes
    
> Stick with octal or hex and you'll be fine (except for \n, and in the case
> of regexes, the regex metacharacters listed in the perlre man page).  I
> only mentioned \cM because you mentioned its use.

Provided your only scripting for ASCII encoded computers you'll be fine with
octal hex or decimal character encodings.  FWIW: the ^ 64 property is not 
shared by most EBCDIC code pages (though it is true for the lower 7 bits 
of UNICODE).

Peter Prymmer


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch