in reply to Reading a run length encoded file in a buffering scenario


I was also playing around with a s/// solution whereby a character would be matched followed by that number of characters. Something like this psuedocode:
my $buffer = "\04perl\03awk\01C"; my @a = $buffer =~ /(.)(.{ord \1})/g;
I tried the following but the assignment of $1 or \1 didn't have an effect.
use re 'eval'; my $buffer = "\04perl\03awk\01C"; my @a = $buffer =~ /(.)(?{$len = ord $1})(.{$len})/g;

Anyone have any ideas about how this could be made to work?

--
John.

Replies are listed 'Best First'.
Re: Re: Reading a run length encoded file in a buffering scenario
by demerphq (Chancellor) on Aug 15, 2002 at 08:45 UTC
    A bit of playing around lead me to this:
    use re 'eval'; my $buffer = "\04perl\03awk\01C"; while ($buffer =~ /\G(.)((??{".{".ord($1)."}"}))/gs) { print ord($1),$2,"\n"; }
    Which seems to work ok. But its cryptic as all get out! (And uses a feature that perlre says is "highly experimental")

    Yves / DeMerphq
    ---
    Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)