I have a large dictionary file, in which each line has a different English language word. The problem I encountered was not the example that follows, the example is much simpler but displays the same characteristic as the problem.
I want to search the file to find all three-letter words that have no repeat characters; i.e., each letter in the word is unique.
Here's my GREP pattern: ^(.)([^\1])[^\1\2]\r
If I understand this right, the (.) is the first character, then ([^ \1]) is any character that is not the same as the first, then [^\1\2] is any character that is not the same as the first or second. (I enclosed the expression in ^ ... \r to exclude three-letter sub- strings.)
The behavior is not as I expected. The returned list contains "aah", "add", "all", and other words with repeated characters. In fact, the list is identical to that I get searching with ^.{3}\r, i.e., all three-letter words.
If I have misunderstood how GREP works, and this is normal behavior, then how do I find words with non-repeats?
On Wed, Oct 08, 2008 at 01:56:43PM -0400, Bull Durham wrote: > Here's my GREP pattern: ^(.)([^\1])[^\1\2]\r
> If I understand this right, the (.) is the first character, then ([^ > \1]) is any character that is not the same as the first, then [^\1\2] > is any character that is not the same as the first or second. (I > enclosed the expression in ^ ... \r to exclude three-letter sub- > strings.)
Character classes, denoted by square brackets, have a completely separate syntax from the main regular expression syntax. A character class is simply a list of individual characters. [^\1] does not mean 'match any character not matched by the first set of capturing parentheses'. It means 'match any character other than 1'.
To do what you want, you should use a negative look-ahead. A negative look-ahead succeeds if the sub-expression does not match at this point in the string. It does not consume any of the string.
Here's how that would look in this case:
^(.)(?!\1)(.)(?!\1|\2)(.)\r
(?!\1) makes sure that the next part of the string does not match whatever was captured in \1.
If you want to dig deeper, check out Jeffrey Friedl's "Mastering Regular Expressions": http://oreilly.com/catalog/9780596528126/index.html. It's a lot of info, but well presented and useful. It's a good resource.
No no. In this day and age that's a bit like telling someone to learn KOBOL. If you want to learn a language, you learn php or ruby. Then, if you really need some super text processing, cobbling it together in perl is pretty easy. But LEARN perl? That's so 1994.
(half, but only half, kidding)
-- "Katrina, $4 gas, a trillion dollar war, rising unemployment, deregulated housing market, global warming...NO MORE!" http://is.gd/2mxY
On 8/10/08 at 8:03 PM -0600, Lewis@Gmail <gkr...@gmail.com> wrote:
>No no. In this day and age that's a bit like telling someone >to learn KOBOL. If you want to learn a language, you learn >php or ruby. Then, if you really need some super text >processing, cobbling it together in perl is pretty easy. But >LEARN perl? That's so 1994.
[If I didn't know better I'd say a large troll just stumbled through the room. I said to the troll; it really doesn't make any sense that you are here! As the troll was leaving I whispered, telling someone to learn php is like saying to learn BASIC.]
Maybe you could say *why* perl is not worth learning other than stating it's a mature language. Why is maturity a bad thing? Why do you think the other languages are better? It could be argued that choosing a programming language based on age should be like choosing a good scotch.
And for anyone else listening and thinking perl is as an archaic language. That is false; it is very much a modern language and worth learning.
And BBEdit has always been a great tool for working with Perl (even in pre-OSX days). [Gotta try to at least stay on topic. ;-)]
Charlie
PS. I've seen Perl web apps that shake the rails from underneath Ruby. [I think another troll just popped up. Go away troll. ;-)] -- Charlie Garrison <garri...@zeta.org.au> PO Box 141, Windsor, NSW 2756, Australia
2008/10/9 Charlie Garrison <garri...@zeta.org.au>:
> Good afternoon,
> On 8/10/08 at 8:03 PM -0600, Lewis@Gmail <gkr...@gmail.com> wrote:
>>No no. In this day and age that's a bit like telling someone >>to learn KOBOL. If you want to learn a language, you learn >>php or ruby. Then, if you really need some super text >>processing, cobbling it together in perl is pretty easy. But >>LEARN perl? That's so 1994.
> [If I didn't know better I'd say a large troll just stumbled > through the room. I said to the troll; it really doesn't make > any sense that you are here! As the troll was leaving I > whispered, telling someone to learn php is like saying to learn BASIC.]
PHP Rocks! (And BBEdit is good for editing it.)
Aren't we all meant to be learning Python these days anyway?
>> On Oct 9, 2008, at 11:04 AM, Carlton Gibson wrote:
>>> Sorry, history of computer science lesson here but, what was LISP >>> then? -- All in the name of things to do with BBEdit of course.
>> The reason we have emacs :)
> No, that's too clever for me... I just don't have the background. I'm > going to have to ask you to explain.
> Carlton > Who started with Dreamweaver and is working backwards.
EMACS (http://www.gnu.org/emacs) is a giant environment originally meant as a text editor. It was written in LISP, all configuration in LISP, all extensions written in LISP. It's still an editor, but now it's considered an OS providing you access to email, IRC, IM, games, databases, et al...
The thing is a giant LISP interpreter.
But back to the topic, Smalltalk is considered the first fully implemented, purely object oriented programming language. There were others, Simula was one of the first to introduce concepts later used in object oriented languages such as Smalltalk, python, java, etc. Simula influenced the object orientation found in later versions of lisp, known as object-lisp.
The concept of perl, I find perl object orientation hacky, a second thought add on to appease people. Perl's strength, it's flexibility is often what I hate most about it. Sure you can write this code in all kinds of fun obfuscated, hard to read, l33t ways, good for you. I won't touch it and it will be replaced. I know plenty of perl people who can't write clean code, they only know perl and can't grasp other languages because they've spent too much time exploiting all the flexibility in perl. That's their weakness, not of the language. The lack of coherency in perl is a major flaw, in my opinion.
> EMACS (http://www.gnu.org/emacs) is a giant environment originally > meant as a text editor. It was written in LISP, all configuration in > LISP, all extensions written in LISP. It's still an editor, but now > it's considered an OS providing you access to email, IRC, IM, games, > databases, et al...
> The thing is a giant LISP interpreter.
> But back to the topic, Smalltalk is considered the first fully > implemented, purely object oriented programming language. There were > others, Simula was one of the first to introduce concepts later used > in object oriented languages such as Smalltalk, python, java, etc. > Simula influenced the object orientation found in later versions of > lisp, known as object-lisp.
On Thu, Oct 9, 2008 at 09:04, Carlton Gibson <carlton.gib...@gmail.com> wrote: > 2008/10/9 William Reveal <w...@wereveal.com>: >> We are all suppose to learn Squeak (opensource Smalltalk) so we get a >> good feel for where all modern OOP languages got their start *grin*
> Sorry, history of computer science lesson here but, what was LISP > then? -- All in the name of things to do with BBEdit of course.
<der...@realgeeky.com> wrote: >The concept of perl, I find perl object orientation hacky, a >second thought add on to appease people. Perl's strength, >it's flexibility is often what I hate most about it. Sure you >can write this code in all kinds of fun obfuscated, hard to >read, l33t ways, good for you. I won't touch it and it will >be replaced. I know plenty of perl people who can't write >clean code, they only know perl and can't grasp other >languages because they've spent too much time exploiting all >the flexibility in perl. That's their weakness, not of the >language. The lack of coherency in perl is a major flaw, in >my opinion.
I'd have to agree with a lot of that in principle. But as Perl has matured, so has many of its programmers. I work with with plenty of other developers (or their code) in the Perl community, and the code is clean, elegant, and easy to read.
As a community, we have learned that just because we *can* write obfuscated code, does not make it a good practice. And compared to the coding style of most php programmers. Well, I'm sure you've all heard the joke. (And that's not a dig at you William; I said *most* php programmers. I know some php programmers who do wonderful things. But as a community....)
As for the object-oriented stuff, for Perl5 it certainly was an add-on. But it still works the way OO is supposed to and the OO syntax works well (easy to read, easy to code, etc). All arguments are off with Perl6 though. That's a completely new code base and launches Perl way out front as 'modern' language.
Hmm, I wonder if the BBSW guys have looked at Perl6 yet and whether the Perl language module needs any changes. I know the Perl language module still has a few bugs with some of the newer Perl5 syntax, so maybe a new version of the language module is pending. :-)
Charlie
-- Charlie Garrison <garri...@zeta.org.au> PO Box 141, Windsor, NSW 2756, Australia
<tedmaster...@gmail.com> wrote: >On Oct 9, 2008, at 9:17 AM, Carlton Gibson wrote:
>> Aren't we all meant to be learning Python these days anyway?
>Oh darn! I thought it was RoR!!! I've been learning the wrong thing!
It seems my whole point got lost among my sarcasm. A language should be chosen based on it's features and whether that will help you get the job done. A language should not be chosen based on how old or young it is or whether your brother's friend is using it.
If it's a good (useful) language; that will continue to be true 10 years later. I started learning Perl 10 years ago and the things that made it a good language then still apply. The things that make a good language today still apply since perl is mature yet still adaptable.
Eg. Perl was written before object-oriented programming was fashionable (same with C). But the language has continued to evolve and is now very good as an object-oriented language. The current OO implementation does leave a bit to be desired (multiple inheritance would have to be classed has a hack), but Perl6 resolves all of that quite elegantly. And adding Moose to Perl5 takes Perl way past OO feature set) many of its current peers. And the code repository (CPAN) is about as comprehensive as it gets. (I dabbled with Ruby and was dismally disappointed by the lack of modules available.)
Anyway, you can tell that I really don't like the "it's an old language" argument since it just doesn't make any sense.
As for practicality and getting the job done; there are plenty of world-class web sites that depend heavily on Perl. It scales just as well (if not better) than PHP. And it scales much better than RoR (as demonstrated by a few high profile sites).
So, if anyone has any actual points (pros/cons) of a given language, then please share. We may have some budding programmers on the list who could benefit from the comparison. But we're probably already veering too far off-topic. This should probably be taken off-list.
Charlie
-- Charlie Garrison <garri...@zeta.org.au> PO Box 141, Windsor, NSW 2756, Australia
On Oct 9, 2008, at 8:09 PM, Charlie Garrison wrote:
> As for the object-oriented stuff, for Perl5 it certainly was an > add-on. But it still works the way OO is supposed to and the OO > syntax works well (easy to read, easy to code, etc). All > arguments are off with Perl6 though. That's a completely new > code base and launches Perl way out front as 'modern' language.
> Hmm, I wonder if the BBSW guys have looked at Perl6 yet and > whether the Perl language module needs any changes. I know the > Perl language module still has a few bugs with some of the newer > Perl5 syntax, so maybe a new version of the language module is > pending. :-)
I very rarely use the word vaporware, but Perl6 is one of those that I definitely consider as vaporware.
It's so hyped, I tend to avoid anyone building it up. At this point, it's a completely different language...why even call it perl? :)
Seriously, when you make that dramatic of a change to the syntax of a language, it pretty much ceases to be that language.
>So, if anyone has any actual points (pros/cons) of a given >language, then please share. We may have some budding >programmers on the list who could benefit from the comparison. >But we're probably already veering too far off-topic. This >should probably be taken off-list.
I like perl. It is a practical extraction and report language that has its place. I use it regularly for preprocessing the content of HTML files downloaded from the web. With curl as the download mechanism I can keep stock reports, broker's statement and the like right in front of me.
I also do some engineering and I find perl useful for that too. It's actually about as useful as FORTRAN was years ago. There is no compile and link stage that really is required only when speed of computation is far more important that speed of development and test.
BBedit to examine the HTML document with search to find the table data that is important followed by creation of regular expressions in perl that find the data between the advertising and a few escapes to shell to execute curl and I'm done.
I do end up using BBEdit's search after selecting and copying stuff from a browser so I can find the proper place in the HTML. That would be a whole lot easier if the search dialog were not modal. I would really like to upgrade but I'm limited to 8.2 or so because I refuse to do away with my SE/30 file server that demands OS 10.3.9 maximum. I am moving toward gedit as a replacement because I can modify that one if I feel like it and ubuntu talks to my SE/30 just fine.
Coming from MPW I am really frustrated that I can't execute a perl script from within an HTML document that I have opened. I have to do that in a worksheet that isn't the same as any other BBEdit document. Cheez. Why not?
I am an occasional contributor to the perl 6 list but it's mostly to complain about ideas involving strange mathematical concepts. Perl 6 wants to do complex numbers and vectors that do not compare to the way physicists and engineers think. Vector multiplication and addition are not even close to what we learn in school. But Newtonian vectors really have no place in a practical extraction and report tool anyway.
As for object orientation. . . It's fine when it helps. But for the fastest solution of an engineering problem it's a real PITA to be forced into some new object when what is really needed is a subroutine with well defined arguments. I couldn't care less about re-usable code. By the time I get it working I have my answer and am never going back.
As for Python. Where in Hell can I find a manual? As far as I can tell all of the subroutines of interest are documented only on the web and I spend more time that I have available to find anything. Programming Perl has it all in the book. I need a new copy because the pages are wearing out.
X-code gives me the same feelings. If I, Apple, haven't provided a way to do what you want you probably can't do it. My life has been doing things that the previous programmers haven't thought about. Perhaps that's why I have written more assembly than compiler code.
And yes. If you have a perl script that works on a file that is opened in BBEdit you can execute it with a line in another window containing a worksheet. When the script quits, BBEdit will reload the altered file from disk. It's a practical way to sort things and add stuff you might not be able to do with a filter. I use that technique for working with wirelists and signals for printed circuit boards. The biggest problem there is that some technical hardware demands both 0A and 0D lineends for separate interpretations in the same file and BBEdit doesn't support that except within its own worksheets.
--
--> A fair tax is one that you pay but I don't <--
<der...@realgeeky.com> wrote: >I very rarely use the word vaporware, but Perl6 is one of those >that I definitely consider as vaporware.
>It's so hyped, I tend to avoid anyone building it up. At this >point, it's a completely different language...why even call it >perl? :)
There was certainly a problem with momentum with that project. It seems to have really been picking up recently though, which is why I mentioned it.
>Seriously, when you make that dramatic of a change to the >syntax of a language, it pretty much ceases to be that language.
I can't really claim to fully understand all the components that make up Perl6, but one of the components allows using different syntax. And of course one of those includes Perl5 syntax. If I understand it right, a lot of the Moose project is stuff back-ported from Perl6 (I could be wrong about that), so anyone using Moose today is already starting to use some of the Perl6 idioms.
Charlie
-- Charlie Garrison <garri...@zeta.org.au> PO Box 141, Windsor, NSW 2756, Australia
<dougl...@macnauchtan.com> wrote: >I like perl. It is a practical extraction and report language >that has its place. I use it regularly for preprocessing the >content of HTML files downloaded from the web. With curl as the >download mechanism I can keep stock reports, broker's statement >and the like right in front of me.
Wow, that was a great example; and completely different to my use of perl for creating webapps.
[BTW, I haven't mentioned Catalyst yet (as a notable benefit of Perl), and anyone would be hard-pressed to find a better web framework in any language.]
Charlie
-- Charlie Garrison <garri...@zeta.org.au> PO Box 141, Windsor, NSW 2756, Australia
> Coming from MPW I am really frustrated that I can't execute a perl > script from within an HTML document that I have opened. I have to do > that in a worksheet that isn't the same as any other BBEdit > document. Cheez. Why not?
Maybe this is not exactly what you're looking for, but I have a simple AppleScript that allows the current selection, or current line if there is no selection, to be executed as a shell command within any BBEdit text window, including the new scratchpad in version 9. This is accomplished by passing the input to AppleScript's "do shell script" command.
Furthermore, if the document's source language is set to PHP/HTML, Perl, or Ruby, the appropriate command line interpreter will be used to execute the input (e.g. "perl -e" for a document with its source language set to Perl).
I'm sure my script could be improved (and I encourage you to share any improvements you might add), but it has served me quite nicely for over a year now. It's very handy to be able to select a line of code and hit a quick keyboard shortcut to execute it in place (I use Cmd- Opt-Ctrl-Return).
If you're interested, you can download the script here:
> On 9/10/08 at 10:38 PM -0400, Derek Belrose > <der...@realgeeky.com> wrote: >> I very rarely use the word vaporware, but Perl6 is one of those >> that I definitely consider as vaporware.
>> It's so hyped, I tend to avoid anyone building it up. At this >> point, it's a completely different language...why even call it >> perl? :)
> There was certainly a problem with momentum with that project. > It seems to have really been picking up recently though, which > is why I mentioned it.
I think the point is that perl6 bears little to know resemblance to, say, perl5.
>> Seriously, when you make that dramatic of a change to the >> syntax of a language, it pretty much ceases to be that language.
> I can't really claim to fully understand all the components that > make up Perl6, but one of the components allows using different > syntax. And of course one of those includes Perl5 syntax.
But this is a kludge thrown in to sort of kind of preserve backwards compatibility with p5, as I understand it. And using p5 syntax you give up p6, no?
-- "Katrina, $4 gas, a trillion dollar war, rising unemployment, deregulated housing market, global warming...NO MORE!" http://is.gd/2mxY