On 24/01/2013 23:26, Adam Engst wrote:

BBEdit and perl FTW! cheers...

As a postscript to this thread I think it’s worth emphasizing how wonderfully simple it is to use Perl RE in text filters by explaining just what is happening. BBEdit has set things up so that the input to the text filter is the whole text of the front document, unless a selection is highlighted, in which case the selection alone is taken as the input and the remainder of the text left intact.

A text filter saved with the suffix .pl or beginning with the shebang #!/usr/bin/perl will be recognized as a Perl filter.

The array (list) of lines in the text is written <STDIN> (= lines in Standard Input) or simply <>, and the ‘while’ block iterates through this array item by item; that is to say it processes the text line by line.

we have:
#!/usr/bin/perl
use strict;
while (<>) {
    # do this; do that; do the other
    s~^(\s*)([a-z])~\U$1$2~; # capitalize the first letter in the line
    print;
}

This means: for each line of input, do these things and write the (modified) line.

Without needing to learn any Perl at all more than this it is thus easy for anybody who has gone to the trouble of learning how to use PCRE in BBEdit to write Perl text filters to do substitutions using what is _almost_ the same lingo. Anyone who does this is bound to get a craving for a little bit more, and again it will be necessary to learn only a tiny bit more Perl syntax at a time and not the whole lot.

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 bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
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 "supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>



Reply via email to