in reply to Regex converting Binary to ASCII


Maybe something like this?:
#!/usr/bin/perl -wl use strict; my $str = 'The ASCII chars 64 and 35'; print $str; $str =~ s/(\d+)/chr $1/eg; print $str; __END__ Prints: The ASCII chars 64 and 35 The ASCII chars @ and #

--
John.

Replies are listed 'Best First'.
Re: Re: Regex converting Binary to ASCII
by tachyon (Chancellor) on Mar 20, 2002 at 11:55 UTC

    You could even add some error checking as ASCII requires that our number be between 0-127

    $str = "Only change valid codes 128 -42 33\n"; print $str; $str =~ s/([+-]?\d+)/ ($1 > 0 and $1 < 128) ? chr $1 : $1 /eg; print $str;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Re: Regex converting Binary to ASCII
by growlf (Pilgrim) on Mar 19, 2002 at 23:34 UTC
    That was it! thanks!

    *G*