azaria has asked for the wisdom of the Perl Monks concerning the following question:

Dear folks I have a special char in the file which is the sop pointer I only know its ascii code (219) How can I write an if statement that check if the line include this specific ascii code? thank in advance azaria

Replies are listed 'Best First'.
Re: ascii in regular expression
by pc88mxer (Vicar) on May 04, 2008 at 07:46 UTC
    if ($line =~ m/\xDB/) { # $line contains character 219 (0xDB in hex) }
Re: ascii in regular expression
by igelkott (Priest) on May 04, 2008 at 09:53 UTC
    ascii code (219)

    As pointed out, that's beyond ascii so it's possibly unicode. While it is certainly \xDB in hex, I'd interpret it as "FULL BLOCK" (aka "graphblock middle"). This is █ as an entity and is displayed as █ (looks like a filled block to me).

    Of course, this certainly isn't standards compliant but might be what you're looking for.

Re: ascii in regular expression
by almut (Canon) on May 04, 2008 at 08:11 UTC
    I only know its ascii code (219)

    <nitpick> This is not ASCII, strictly speaking... (which is 7-bit, and thus only defines codes in the range 0-127) </nitpick>

Re: ascii in regular expression
by ikegami (Patriarch) on May 04, 2008 at 09:00 UTC

    Caveat: The answers already given to you assume you don't decode the bytes you read in (using :encoding(...), decode, use open or some other means) into a string of characters. If so, you'll need to decode chr(219) and compare against that.

Re: ascii in regular expression
by Anonymous Monk on May 04, 2008 at 07:44 UTC
    perl -e'die unpack q=H*=, chr 219' db at -e line 1. perl -e'die 1 if chr(219) =~ /\xDB/' 1 at -e line 1.
Re: ascii in regular expression
by Anonymous Monk on May 04, 2008 at 07:41 UTC