The title almost gets at what I want to do. I have some code at the top of my scratchpad that almost does what I'd like. If I can use the perl metachars, that would be okay, I'm not wedded to the chars I picked for the mapping.
I'd like to express runs of character classes as one char. For example, all contiguous A-Za-z0-9 would be replaced by an 'A', all contiguous \000 replaced by an 'E', all contiguous \377 replaced by an 'F'. I've almost got it, with the code on my scratchpad, but I'm wondering if there's a more efficient way, or a method that will let me get the last coverage I need.
Now, I'm doing this:
# main while(read(FIN,$data,$bsize)) { while (length($data)) { if ($data =~ /^([\d\w]+)/ ) { notate('A', length($1)); } # more if's } } # sub notate { my $c = shift; my $n = shift; if ((! defined $c) || (! defined $n)) { close(FIN); if ($opt_M) { close(FOUT); } print STDERR "$0 : FATAL ERROR in sub notate\n"; exit; } $count{$c} += $n; substr($data,0,$n) = ''; # dangerous if (! $opt_M) { $mstr .= $c; } else { print FOUT "$c"; } return(0); }
In reply to How to express contents of a file as regex metachars? by dwhite20899
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |