Random ideas: an ed in perl?

command line processor ->
[addr1 [,addr2] ] [ [ command ] [ flag ] ]

extract the address start / end range, look up the codref for command
and extract the flag if any.

Use defaults from the table if addresses are omitted / command omitted /
flags omitted / etc.

apply linear commands ->

$cmds{subsitute}->($line, $flag);

each command is applied to a string, $line, and passed any extracted
flag is passed as an option argument to the subref. (e.g. p,n,l, or g)

text marshal/serialize routines ->

if using tempfile:
extract line range into an array of lines

else using memory:
suck file into an array of lines

that array of lines is the text to apply the linear commands to.
the result is then used to update the buffer (array/tempfile)

I/O ->
truncate user file and copy buffer to user file

Bang escape ->
! can be implemented with the gx or `` syntax in perl

notes

pped / ed: if invoked as ed, turn on BRE support.
opts: -s, suppress diagnostics for scripts
-p, set prompt string to 'string'
--regex={basic,perl} set traditional or perl re's
-P set perl re's
-B set basic re's
-S, --map edit file in memory
-n, novice mode: same as 'H' command

doing files in memory sucks the file into an array of lines; basically
a pseudo-mmap. This simplifies the marshal/serialize code, and removes
the need for a temporary file, but causes memory usage to balloon in
proportion to the file size.


S[flag] [value]

set option flag to value; omit flag and value to print all options
P, ps prompt string (str)
B, re use basic regular expressions (int)
N, nl set 'n' marker for writing out lines (int)
H, he same as 'H' command