On 24/01/2013 14:51, Adam Engst wrote:
Man, you're going to make me learn perl grep syntax, aren't you? :-)
Perl regular expressions are the basis of the PCRE used in BBEdit, so
there’s very little to learn if you’re familiar with PCRE. The main
difference is that Perl uses $&, $1, $2 for PCRE’s \0, \1, \2 ; but
you’re probably not using those anyway.
I see roughly how to do it, and I can do simple substitutions in
> perl, but I'm having trouble getting the more complex ones to run.
> I've figured out that you need to dot-combine literal characters with
> grep in the replacements, but I'm getting SCALAR and some numbers
> instead of my grep replacements.
The trouble you’re having is due to your use of ///e, which treats the
substitution pattern as an executable string. Forget about using that,
almost ever. For one thing, servers won’t allow you to use it in CGI
scripts because you could use the trick to blow up their machines or the
world. I’d also forget about using ///x to allow spaces. Just get used
to reading the things. See
http://docstore.mik.ua/orelly/perl/perlnut/ch04_06.htm or read perlretut.
...and there's some distinction between
> /n and /r I'm not yet understanding (since things work better with \n
> than \r, but I always use \r in BBEdit).
You are reading line by line so \r and \n don’t come into it. Every
line ends with a line-ending (!!) and if you want to get rid of it, just
do ;chomp; but you probably don’t. I also use ‘~’ as the delimiter for
RE, because I very rarely have ‘~’ in a document but often have ‘/’s and
don’t want to have to escape them.
s/^Title: / '#' /e;
s~Title: ~#~
s/^Blurb: (.+)/ 'A>' . \1/e;
s~^Blurb: (.+)~'A>'$1~ # ???
I can’t work out quite what you mean by these replacements but it looks
as if you’re making things far more complicated for yourself than you
need to. You know how to use RE patterns, so forget about the few
differences between PCRE and Perl RE, use ‘~’ for convenience instead of
‘/’ and get on with it.
You can make a test filter as below and run it on a frontmost test
document to see what it does. The changes made by the filter can be
undone with ⌘Z. Make sure you save the changes in the filter script
before running it from the palette.
while (<>) {
s~~~g; # g means substitute all
s~~~i; # i means disregard caSe
s~~~g;
}
Hope this is readable. I hate Thunderbird and I hate Mail even more.
10.8 has robbed me of the only mail program that was ever any good.
JD
--
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>