in reply to Emacs Outline Mode Header Numbering
The item on the right of an s///e is a full block, so you don't need to haggle it all into a single expression. Thus, using a more natural coding style, this would be:!/usr/bin/perl -w -p s/^(\*+)/ $n = length($1), $n < $o ? @l[$n+1..$#l] = (0)x($#l-$n) : 0, $l[$n]++, $o = $n, join(".",@l[1..$n]) /e;
I see a possibility (I think) of having only one global rather than two, but I'm not quite ready to rewrite that yet... just wanted to show the isomorphic equivalent of your code in a cleaner syntax.!/usr/bin/perl -w -p s { ^(\*+) # look for stars at the beginning of line }{ my $n = length($1); # get number of stars @l[$n+1..$#l] = (0)x($#l-$n) if $n < $o; # @l is global $l[$n]++; $o = $n; # $o is global join(".",@l[1..$n]); # returning this }ex;
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Emacs Outline Mode Header Numbering
by clemburg (Curate) on Jun 12, 2001 at 12:10 UTC |