Re: perl qstn...
On Fri, Apr 9, 2010 at 5:56 AM, Randal L. Schwartz wrote: >> "Alejandro" == Alejandro Imass writes: > > Alejandro> did you mean unless? ;-) > > Did you read this: > >>> Augh. I hit send just as I realized that's backwards. Need >>> more caffiene. Swap the true and false blocks there. :) > Yeah, but _after_ I had pressed send . That sparked the comment that unless was a bad idea in C and then all helll broke loose > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > http://www.stonehenge.com/merlyn/> > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Alejandro" == Alejandro Imass writes: Alejandro> did you mean unless? ;-) Did you read this: >> Augh. I hit send just as I realized that's backwards. Need >> more caffiene. Swap the true and false blocks there. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Wed, 7 Apr 2010 19:15:05 -0600 Chad Perrin wrote: > On Wed, Apr 07, 2010 at 01:09:54PM +0100, RW wrote: > > On Tue, 6 Apr 2010 21:07:17 -0600 > > Chad Perrin wrote: > > > > > On Tue, Apr 06, 2010 at 01:20:49PM +0100, RW wrote: > > > > On Mon, 5 Apr 2010 19:55:44 -0600 > > > > Chad Perrin wrote: > > > > > > > > > On Mon, Apr 05, 2010 at 05:36:32PM +0100, RW wrote: > > > > > > > There are more things in heav'n and earth, Horatio, than are > > > > > dreamt of by designers of eagerly evaluated prefix notation > > > > > languages. > > > > > > > > And most of them are obscure for good reasons. Just because a a > > > > syntax fits into a classification scheme doesn't make it a good > > > > idea. > > > > > Shall we trade more trite sniping, or would you like to say > > > something more substantive? > > > > You started it. > > 1. No, I used a misquote to lead into a lengthy explanation. > You started with a patronising misquote implying ignorance of wider context. > > I'm not, I'm expressing an opinion that this is not a feature worth > > copying. > > Judging by your further disputations with Mr. Schwartz, I don't think > I believe you. I can live with that. If I don't think it worth copying, I'm not going to like it in perl. That's not the same as telling you what you should and shouldn't do. I don't use perl or python all that much, and I wasn't aware of quite how religious an issue this is. I thought I was commenting on a perl feature, but it appears to have been interpreted as an attack on your faith. > > > Frankly, if everybody just stuck to a purely "natural order of > > > decision" approach to imperative language design, we would never > > > even have developed structured programming. > > > > I have no idea what you trying to say here. I presume it must be > > some kind of straw man argument. > > It's not a straw man argument. Your presumption is wrong. Then your comment is simply noise. Most structured languages get by without the feature I'm referring to, and I've made it clear I'm not talking about ordering in any other context. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Wed, Apr 07, 2010 at 01:09:54PM +0100, RW wrote: > On Tue, 6 Apr 2010 21:07:17 -0600 > Chad Perrin wrote: > > > On Tue, Apr 06, 2010 at 01:20:49PM +0100, RW wrote: > > > On Mon, 5 Apr 2010 19:55:44 -0600 > > > Chad Perrin wrote: > > > > > > > On Mon, Apr 05, 2010 at 05:36:32PM +0100, RW wrote: > > > > > There are more things in heav'n and earth, Horatio, than are > > > > dreamt of by designers of eagerly evaluated prefix notation > > > > languages. > > > > > > And most of them are obscure for good reasons. Just because a a > > > syntax fits into a classification scheme doesn't make it a good > > > idea. > > > Shall we trade more trite sniping, or would you like to say something > > more substantive? > > You started it. 1. No, I used a misquote to lead into a lengthy explanation. 2. Seriously? Are you not aware of how juvenile that sounds? > > > > > > Natural languages are mostly driven by spoken usage, in which people > > > firm-up half-formed ideas as they speak - this is not a good model > > > for programming languages. If you are hacking out a quick and dirty > > > script it may be convenient to type the decision after the action, > > > but it don't I think it promotes good quality software. > > > > This sounds exactly like the complaints Pythonistas use to explain why > > they have a deep hatred of Perl. If that's how you feel, I'd prefer > > you stop trying to tell me how Perl should work, and just use > > something else. > > I'm not, I'm expressing an opinion that this is not a feature worth > copying. Judging by your further disputations with Mr. Schwartz, I don't think I believe you. > > > > Imperative languages have a natural order of decision followed by > > > action, and code is most easily readable if the syntax doesn't try > > > to subvert that. > > > > . . . except when the "natural order of decision" varies > > significantly, such as when comparing functions with operators. It > > gets even more confusing when both "functions" and "operators" are > > actually methods in object oriented languages with an imperative > > design, because suddenly the difference between a "function" and an > > "operator" becomes purely arbitrary. There's nothing about > > arbitrariness that suggests a "natural order". > > Expression are different. When you are trying to understand thousands > of lines of code, the order of execution within an expression is fine > detail, but the flow of execution is something that needs to be > taken-in easily. This doesn't change anything I said. > > > It's kind of odd you rail against natural language then talk about > > I'm not railing again natural languages, I just don't think they have > much relevance. It's kind of odd you rail against natural language *in this context*. I thought "in this context" was obvious. > > > imperative languages having a "natural order" -- which is, presumably, > > based on the expectations of people who have been conditioned to think > > that way by their use of natural language. > > No, it's conditioned by causality, and other mainstream programming > languages. > > People juggle a lot of languages, being different for the sake of it > isn't very helpful. Who said anything about being different for the sake of being different? If you find it too difficult to actually respond to what I said, please refrain from responding. > > > Frankly, if everybody just stuck to a purely "natural order of > > decision" approach to imperative language design, we would never even > > have developed structured programming. > > I have no idea what you trying to say here. I presume it must be some > kind of straw man argument. It's not a straw man argument. Your presumption is wrong. I have no idea how what I said could not be perfectly obvious. It's pretty clear. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpv6MIox8pkk.pgp Description: PGP signature
Re: perl qstn...
On Tue, Apr 6, 2010 at 5:10 PM, Randal L. Schwartz wrote: >> "Chuck" == Chuck Swiger writes: > [...] > Now, on the other hand, emacs rules, vi sucks. :-) :-) you got that right bud! oh, and the Perl stuff too ;-) > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > http://www.stonehenge.com/merlyn/> > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Tue, Apr 06, 2010 at 09:01:10PM -0600, Chad Perrin wrote: > On Tue, Apr 06, 2010 at 06:17:41PM -0400, Steve Bertrand wrote: > > On 2010.04.06 17:10, Randal L. Schwartz wrote: > > > > > Now, on the other hand, emacs rules, vi sucks. :-) :-) > > > > ok, ok. I was on the side of Perl, and was content following this > > thread, but now I don't like you anymore :P > > > > heh ;) > > > > Steve > > I'm willing to let the emacs users have their emacs, and to enjoy my vi. > I guess the longer name (emacs) suits people who like pressing more > buttons to accomplish the same amount of work anyway. > besides all this, someone can use vi easily with only one hand---or just a few fingers for those of us who still hunt-and-peck. with emacs, gotta have at least 17 hands. > -- > Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.79a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Tue, 6 Apr 2010 21:07:17 -0600 Chad Perrin wrote: > On Tue, Apr 06, 2010 at 01:20:49PM +0100, RW wrote: > > On Mon, 5 Apr 2010 19:55:44 -0600 > > Chad Perrin wrote: > > > > > On Mon, Apr 05, 2010 at 05:36:32PM +0100, RW wrote: > > > There are more things in heav'n and earth, Horatio, than are > > > dreamt of by designers of eagerly evaluated prefix notation > > > languages. > > > > And most of them are obscure for good reasons. Just because a a > > syntax fits into a classification scheme doesn't make it a good > > idea. > Shall we trade more trite sniping, or would you like to say something > more substantive? You started it. > > > > Natural languages are mostly driven by spoken usage, in which people > > firm-up half-formed ideas as they speak - this is not a good model > > for programming languages. If you are hacking out a quick and dirty > > script it may be convenient to type the decision after the action, > > but it don't I think it promotes good quality software. > > This sounds exactly like the complaints Pythonistas use to explain why > they have a deep hatred of Perl. If that's how you feel, I'd prefer > you stop trying to tell me how Perl should work, and just use > something else. I'm not, I'm expressing an opinion that this is not a feature worth copying. > > Imperative languages have a natural order of decision followed by > > action, and code is most easily readable if the syntax doesn't try > > to subvert that. > > . . . except when the "natural order of decision" varies > significantly, such as when comparing functions with operators. It > gets even more confusing when both "functions" and "operators" are > actually methods in object oriented languages with an imperative > design, because suddenly the difference between a "function" and an > "operator" becomes purely arbitrary. There's nothing about > arbitrariness that suggests a "natural order". Expression are different. When you are trying to understand thousands of lines of code, the order of execution within an expression is fine detail, but the flow of execution is something that needs to be taken-in easily. > It's kind of odd you rail against natural language then talk about I'm not railing again natural languages, I just don't think they have much relevance. > imperative languages having a "natural order" -- which is, presumably, > based on the expectations of people who have been conditioned to think > that way by their use of natural language. No, it's conditioned by causality, and other mainstream programming languages. People juggle a lot of languages, being different for the sake of it isn't very helpful. > Frankly, if everybody just stuck to a purely "natural order of > decision" approach to imperative language design, we would never even > have developed structured programming. I have no idea what you trying to say here. I presume it must be some kind of straw man argument. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Tue, Apr 06, 2010 at 01:20:49PM +0100, RW wrote: > On Mon, 5 Apr 2010 19:55:44 -0600 > Chad Perrin wrote: > > > On Mon, Apr 05, 2010 at 05:36:32PM +0100, RW wrote: > > > > > > IMO this is a bad mistake that other languages were quite right not > > > to copy - a test shouldn't come after a block of code unless it's > > > evaluated after the block (as in repeat...until) > > > > There are more things in heav'n and earth, Horatio, than are dreamt > > of by designers of eagerly evaluated prefix notation languages. > > And most of them are obscure for good reasons. Just because a a syntax > fits into a classification scheme doesn't make it a good idea. The fact something is popular doesn't mean it's a good idea. Shall we trade more trite sniping, or would you like to say something more substantive? In no way, and at no time, did I imply that using "unless" like an infix operator is a good idea just because it fits with a given syntax classification. > > Natural languages are mostly driven by spoken usage, in which people > firm-up half-formed ideas as they speak - this is not a good model for > programming languages. If you are hacking out a quick and dirty script > it may be convenient to type the decision after the action, but it > don't I think it promotes good quality software. This sounds exactly like the complaints Pythonistas use to explain why they have a deep hatred of Perl. If that's how you feel, I'd prefer you stop trying to tell me how Perl should work, and just use something else. > > Imperative languages have a natural order of decision followed by > action, and code is most easily readable if the syntax doesn't try to > subvert that. . . . except when the "natural order of decision" varies significantly, such as when comparing functions with operators. It gets even more confusing when both "functions" and "operators" are actually methods in object oriented languages with an imperative design, because suddenly the difference between a "function" and an "operator" becomes purely arbitrary. There's nothing about arbitrariness that suggests a "natural order". It's kind of odd you rail against natural language then talk about imperative languages having a "natural order" -- which is, presumably, based on the expectations of people who have been conditioned to think that way by their use of natural language. Frankly, if everybody just stuck to a purely "natural order of decision" approach to imperative language design, we would never even have developed structured programming. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpEUjI65NlvI.pgp Description: PGP signature
Re: perl qstn...
On Tue, Apr 06, 2010 at 06:17:41PM -0400, Steve Bertrand wrote: > On 2010.04.06 17:10, Randal L. Schwartz wrote: > > > Now, on the other hand, emacs rules, vi sucks. :-) :-) > > ok, ok. I was on the side of Perl, and was content following this > thread, but now I don't like you anymore :P > > heh ;) > > Steve I'm willing to let the emacs users have their emacs, and to enjoy my vi. I guess the longer name (emacs) suits people who like pressing more buttons to accomplish the same amount of work anyway. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpwq7ywxcB58.pgp Description: PGP signature
Re: perl qstn...
On 2010.04.06 17:10, Randal L. Schwartz wrote: > Now, on the other hand, emacs rules, vi sucks. :-) :-) ok, ok. I was on the side of Perl, and was content following this thread, but now I don't like you anymore :P heh ;) Steve ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Chuck" == Chuck Swiger writes: Chuck> Very well; I would like to hear you propose another type of Chuck> change that might be made to this sort of postfix test syntax Chuck> which you consider to be "most likely". Maybe the content of the text message. I change that stuff all the time. Or maybe the exact nature of the condition. That also changes. Let me short cut the rest of the discussion, by summarizing: You and and I have different "favorite languages" However, our positions are different about the fact that we have different "favorite languages". I'm perfectly willing to let you have Python, and work productively in it, while I'm happily being productive with Perl. I'm also perfectly willing to allow you imagine faults with Perl, even though after having used Perl productively for 20 years, those problems just don't arise in practice. You, on the other hand, seem to want to convince me that I couldn't have possibly been as productive in Perl as I have for the past 20 years, because of these alleged insurmountable problems. You seem to want to ensure that whatever my experience of Perl might be, that it is somehow wrong or tainted or misinformed. Hmm. Really? Really? Now, in the greater range of things, which position is more useful? Can we agree that we've gone *way beyond* the topic of freebsd-questions as well, and if anyone hasn't killfiled us already, they should have? :-) Now, on the other hand, emacs rules, vi sucks. :-) :-) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Apr 6, 2010, at 11:43 AM, Randal L. Schwartz wrote: > "Chuck" == Chuck Swiger writes: >> Then you wouldn't have used this construct. > > Chuck> If the construct isn't a good idea considering the most obvious > Chuck> change one might make to the code, > > Objection: presumes facts not in evidence, your honor. This isn't a court-room. I don't mind rhetorical flourishes, but if you are unwilling to consider how a statement might be changed over time as the circumstances require, even for the sake of discussion, well, in doing so you've chosen to not consider code maintainability. > Seriously, I've written thousands of lines that look like: > > print "." if $flag; > > over the years (decades), and only *once* or *twice* do I ever recall > saying "oh, I actually wanted a two-way switch", and had to rewrite it. > > So "most obvious" to you is clearly not what is actually most likely. Very well; I would like to hear you propose another type of change that might be made to this sort of postfix test syntax which you consider to be "most likely". I find it remarkable, and nearly unbelievable, that one would only need to add an else clause to such a statement less often than 0.1% of the time. Frankly, I wouldn't mind taking a look through a few revisions of something you'd written (perhaps via CVSweb or similar) to see what kind of changes you do make to code over time. > Chuck> Surely Perl source code shouldn't be considered as write-once, > Chuck> modify-never? > > Yes, and that's also presumes facts not in evidence. See above. I'd be happy to take a look at your evidence. In fact, I'd already asked a similar question: >> Perl has *many* options that are all clear and readable, and some >> that aren't. Python has a *few* options that are all clear and >> readable, and some that aren't. > > ...and an example or two would be? ...and yet I do not see a response. Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Chuck" == Chuck Swiger writes: >> >> Then you wouldn't have used this construct. Chuck> If the construct isn't a good idea considering the most obvious Chuck> change one might make to the code, Objection: presumes facts not in evidence, your honor. Seriously, I've written thousands of lines that look like: print "." if $flag; over the years (decades), and only *once* or *twice* do I ever recall saying "oh, I actually wanted a two-way switch", and had to rewrite it. So "most obvious" to you is clearly not what is actually most likely. This undermines the rest of your argument, but let's read on... Chuck> Surely Perl source code shouldn't be considered as write-once, Chuck> modify-never? Yes, and that's also presumes facts not in evidence. See above. Chuck> I would suggest that good software not only allows the user the Chuck> full freedom to do anything which is possible, it should also Chuck> avoid asking the user about choices which are Chuck> impossible/invalid/wrong/etc. This can be input field Chuck> validation, middleware logic, this can be determining the present Chuck> state and greying out options which are not currently applicable, Chuck> etc. I agree. The difference with Perl is that there are often many equally good ways to choose. If that's too much repsonsibility for you, please don't use Perl. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Apr 6, 2010, at 11:07 AM, Randal L. Schwartz wrote: >> "Chuck" == Chuck Swiger writes: > Chuck> Let's suppose you want to display one message if debugging is > Chuck> enabled, and a shorter message if it is not. > > Then you wouldn't have used this construct. If the construct isn't a good idea considering the most obvious change one might make to the code, I would conclude that it's probably never going to be a good idea to use such a thing. Surely Perl source code shouldn't be considered as write-once, modify-never? >>> If you don't like all this freedom, there's always Python. :) > > Chuck> Yes, Perl lets you innovate a remarkable number of ways of > Chuck> solving the same problem using syntax that varies from clean and > Chuck> maintainable to constructs which even the original author won't > Chuck> understand without effort a few months later. It seems to be > Chuck> uncommon for one to write unreadable Python code; I'm not sure > Chuck> additional freedom to write obfuscated code would be as > Chuck> beneficial as one may assume > > I call shenanigans: False dichotomy. I agree: the assertion you've made that Python lacks freedom is a false dichotomy. As we all know, any language which is adequately expressive can be used to write arbitrary code; much less languages which permit callouts or extension mechanisms to invoke native C/assembler/etc code. If you really find an advantage in obfuscated syntax and regard it as representing more freedom, I won't argue that opinion with you directly, but instead ask that you demonstrate that this supposed freedom results in better code, ease of maintainability, etc: > Perl has *many* options that are all clear and readable, and some > that aren't. Python has a *few* options that are all clear and > readable, and some that aren't. ...and an example or two would be? > You may not appreciate that freedom. Others do. With freedom comes > responsibility. If that's not for you, Perl's not for you. I would suggest that good software not only allows the user the full freedom to do anything which is possible, it should also avoid asking the user about choices which are impossible/invalid/wrong/etc. This can be input field validation, middleware logic, this can be determining the present state and greying out options which are not currently applicable, etc. Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Chuck" == Chuck Swiger writes: Chuck> Let's suppose you want to display one message if debugging is Chuck> enabled, and a shorter message if it is not. Then you wouldn't have used this construct. >> If you don't like all this freedom, there's always Python. :) Chuck> Yes, Perl lets you innovate a remarkable number of ways of Chuck> solving the same problem using syntax that varies from clean and Chuck> maintainable to constructs which even the original author won't Chuck> understand without effort a few months later. It seems to be Chuck> uncommon for one to write unreadable Python code; I'm not sure Chuck> additional freedom to write obfuscated code would be as Chuck> beneficial as one may assume I call shenanigans: False dichotomy. Perl has *many* options that are all clear and readable, and some that aren't. Python has a *few* options that are all clear and readable, and some that aren't. You may not appreciate that freedom. Others do. With freedom comes responsibility. If that's not for you, Perl's not for you. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
Hi-- On Apr 6, 2010, at 6:21 AM, Randal L. Schwartz wrote: >> "RW" == RW writes: > RW> Imperative languages have a natural order of decision followed by > RW> action, and code is most easily readable if the syntax doesn't try to > RW> subvert that. > > And yet, there's an equally valid argument that the most important > thing should stand out the most. In that sense, in the Perl statement: > > warn "x = $x, y = $y, z = $z\n" >if $debug; > > ... the most important part is that it's printing something to stderr, > and what's being printed. It's only minor that it's only when > debugging, and luckily Perl lets us relegate that to the tail end of > the statement. > > Now, if you argue "oh, the most important thing there is 'if debug'", > then fine, you'd write that as: > > if ($debug) { warn ... } > > And I'd be fine with that. Let's suppose you want to display one message if debugging is enabled, and a shorter message if it is not. Adding an else clause to an if statement is a natural change and the result remains highly readable. Can one even use this postfix test syntax with an else, or would you have to re-write the first version entirely? As far as I am concerned, the first version resembles exception handling, ie: try: except Error1: ...and should be reserved for situations where the statement is expected to run normally. If it is reasonable that the test might fail more often than in unusual circumstances, then I'd really prefer to put the test first. > If you don't like all this freedom, there's always Python. :) Yes, Perl lets you innovate a remarkable number of ways of solving the same problem using syntax that varies from clean and maintainable to constructs which even the original author won't understand without effort a few months later. It seems to be uncommon for one to write unreadable Python code; I'm not sure additional freedom to write obfuscated code would be as beneficial as one may assume Regards, -- -Chuck ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Giorgos" == Giorgos Keramidas writes: Giorgos> This means you can write your sh version like this in Perl: Giorgos> #!/usr/bin/perl Giorgos> if (int(@ARGV) == 0) { Giorgos> die "No args; at least one filename expected"; Giorgos> } Giorgos> printf("%s\n", join(' ', (@ARGV))); Which, when you're not speaking Perl with a C accent, expressed more "natively" as: @ARGV or die "No args: at least one filename expected"; print "@ARGV\n"; -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, 04 Apr 2010 02:01:53 -0700, Gary Kline wrote: > thanks for your url as well and the others to posted. but it seems > like overkill since i dont need any explicit option or argument. i > just need the script to tell me whether i have an arg or not. > following is something i've kept in one of my junk drawers from when i > was learning to write bourne sscripts. it uses the "$[token]" syntax > that determines whether there are Any args on the cmdline. if not, > the script prints a message and exits. > > #!/bin/sh > if [ $# -eq 0 ] > then > echo "No args; need filename." > else > echo "$1" > fi > > After a couple hours experimentation, the following does the same for my > perl scripts: > > > #!/usr/bin/perl > $argc = @ARGV; > if (! $argc ) { > printf("No args; need filename.\n"); > } > else { > printf("%s\n", @ARGV); > } Yes, that's very close to the sh(1) version. Perl's behavior in this case is described in the 'perlvar' manpage: @ARGV The array @ARGV contains the command-line arguments intended for the script. $#ARGV is generally the number of arguments minus one, because $ARGV[0] is the first argument, not the program's command name itself. See $0 for the command name. In other words, when @ARGV appears in "scalar context" it yields the 'size' of the @ARGV array, e.g.: % cat foo.pl printf("%d .. args = [%s]\n", int(@ARGV), join(', ', (@ARGV))); % perl foo.pl 0 .. args = [] % perl foo.pl 1 1 .. args = [1] % perl foo.pl 1 2 3 3 .. args = [1, 2, 3] So when int(@ARGV) is zero you know that there are no arguments at all. This means you can write your sh version like this in Perl: #!/usr/bin/perl if (int(@ARGV) == 0) { die "No args; at least one filename expected"; } printf("%s\n", join(' ', (@ARGV))); This is "good enough" as a command-line handling trick for really simple scripts, but you should probably have a look at the Getopt::Std and the Getopt::Long modules for longer scripts. Using them will make your option parsing code much cleaner and easier to change in the future. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "RW" == RW writes: RW> Imperative languages have a natural order of decision followed by RW> action, and code is most easily readable if the syntax doesn't try to RW> subvert that. And yet, there's an equally valid argument that the most important thing should stand out the most. In that sense, in the Perl statement: warn "x = $x, y = $y, z = $z\n" if $debug; ... the most important part is that it's printing something to stderr, and what's being printed. It's only minor that it's only when debugging, and luckily Perl lets us relegate that to the tail end of the statement. Now, if you argue "oh, the most important thing there is 'if debug'", then fine, you'd write that as: if ($debug) { warn ... } And I'd be fine with that. But I tend to see that layout as a lot of noise just to add a minor conditional. Or you could speak Perl with a Shell accent, and say $debug and warn ...; Fine, that also works, and some part of your audience will hate you, and another part will be totally cool with it. But this *is* the reason There's More Than One Way To Do It in Perl. You can write Perl that most naturally expresses what you believe is important in the code. If you don't like all this freedom, there's always Python. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Mon, 5 Apr 2010 19:55:44 -0600 Chad Perrin wrote: > On Mon, Apr 05, 2010 at 05:36:32PM +0100, RW wrote: > > > > IMO this is a bad mistake that other languages were quite right not > > to copy - a test shouldn't come after a block of code unless it's > > evaluated after the block (as in repeat...until) > > There are more things in heav'n and earth, Horatio, than are dreamt > of by designers of eagerly evaluated prefix notation languages. And most of them are obscure for good reasons. Just because a a syntax fits into a classification scheme doesn't make it a good idea. Natural languages are mostly driven by spoken usage, in which people firm-up half-formed ideas as they speak - this is not a good model for programming languages. If you are hacking out a quick and dirty script it may be convenient to type the decision after the action, but it don't I think it promotes good quality software. Imperative languages have a natural order of decision followed by action, and code is most easily readable if the syntax doesn't try to subvert that. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 06/04/2010 02:55:44, Chad Perrin wrote: > 3. lazy evaluation, where the (result) is not evaluated until it is > needed, which gives the interpreter plenty of time to notice there's > an "unless" immediately following it > > Obviously, the "real" answer in the case of Ruby and Perl falls somewhere > around 1.5, but 3 is still a believable-sounding excuse, and perfectly > acceptable to me. perl (and ruby) are byte-compiled languages, not interpreted languages (like sh). All ordering variations on if and unless statements should end up using pretty much the same sequence of opcodes once parsed and compiled. Cheers, Matthew - -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW -BEGIN PGP SIGNATURE- Version: GnuPG/MacGPG2 v2.0.14 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAku61VIACgkQ8Mjk52CukIwLPQCfXW15dHTRMRfIENyT//OrzzAz qYAAnjYjiRsS2jq9XaJ2xN15sM1BDc6K =3PnR -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Mon, Apr 05, 2010 at 05:36:32PM +0100, RW wrote: > > IMO this is a bad mistake that other languages were quite right not to > copy - a test shouldn't come after a block of code unless it's evaluated > after the block (as in repeat...until) There are more things in heav'n and earth, Horatio, than are dreamt of by designers of eagerly evaluated prefix notation languages. Actually, I'd think that using "unless" that way would be right up the alley of the users of most programming languages, since "unless" is here just being used the same way as an infix notation operator with very high precedence. If you want to get rigorous about it, I'd prefer this approach: unless (condition) (result) . . . where it uses strict prefix notation. I know that some people think postfix notation is the bee's knees because of implementation reasons, but frankly, implementation should be something we never have to see, in my opinion -- unless we're actually implementing it. Computers are for scut work; humans are for idea work. Failing strict prefix notation, I'm okay with the way Perl and Ruby use "unless". This: (result) unless (condition) . . . could be explained away as fitting with any of: 1. conforming to natural language expectations, thus leaving implementation scut-work to the realm of the computer 2. infix notation with very high precedence for "unless" 3. lazy evaluation, where the (result) is not evaluated until it is needed, which gives the interpreter plenty of time to notice there's an "unless" immediately following it Obviously, the "real" answer in the case of Ruby and Perl falls somewhere around 1.5, but 3 is still a believable-sounding excuse, and perfectly acceptable to me. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpKFRwk4tO9r.pgp Description: PGP signature
Re: perl qstn...
On Mon, 05 Apr 2010 09:57:17 +0100 Matthew Seaman wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > I've always found that 'unless' makes a great deal of sense when used > in the alternate syntax: > > do_foo() > unless $condition ; > > As far as I know, perl and its descendant ruby are the only > programming languages that let you put the condition test after the > action, IMO this is a bad mistake that other languages were quite right not to copy - a test shouldn't come after a block of code unless it's evaluated after the block (as in repeat...until) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
in message <867homm1qf@red.stonehenge.com>, wrote Randal L. Schwartz thusly... > > > "Matthew" == Matthew Seaman > > writes: > > Matthew> As far as I know, perl and its descendant ruby are the > Matthew> only programming languages that let you put the > Matthew> condition test after the action, despite this being > Matthew> exceeding familiar in human languages. > > Except, we old-timers remember that Larry Wall directly lifted this > from RSTS-E BASIC-PLUS, which he had used at Pacific University as a > student. Having hacked BASIC-PLUS myself around the same time, I > recognized it instantly. > > BASIC-PLUS went further though, allowing them to be nested. So > you'd end up with monstrosities like: "Beauty is in the eye ...", or, perhaos you would prefer "Only a mother would ...". > PRINT a > IF a % 3 = 2 > FOR a = b TO b+7 > FOR b = 0 TO 90 STEP 10; Oh Randal, don't tease me please about the lack of such loveliness in perl. - parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Matthew" == Matthew Seaman writes: Matthew> As far as I know, perl and its descendant ruby are the only Matthew> programming languages that let you put the condition test after Matthew> the action, despite this being exceeding familiar in human Matthew> languages. Except, we old-timers remember that Larry Wall directly lifted this from RSTS-E BASIC-PLUS, which he had used at Pacific University as a student. Having hacked BASIC-PLUS myself around the same time, I recognized it instantly. BASIC-PLUS went further though, allowing them to be nested. So you'd end up with monstrosities like: PRINT a IF a % 3 = 2 FOR a = b TO b+7 FOR b = 0 TO 90 STEP 10; Thankfully, Larry limited Perl's statement modifiers to precisely one level. :) Just another old geezer, -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 04/04/2010 19:48:14, Alejandro Imass wrote: > But honestly pun aside unless(){} is far more readable than if(!){} > and _especially_ if you are programming in an exception manner as you > correctly point out. Every language should have an unless construct. I've always found that 'unless' makes a great deal of sense when used in the alternate syntax: do_foo() unless $condition ; As far as I know, perl and its descendant ruby are the only programming languages that let you put the condition test after the action, despite this being exceeding familiar in human languages. Cheers, Matthew - -- Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW -BEGIN PGP SIGNATURE- Version: GnuPG/MacGPG2 v2.0.14 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAku5pe0ACgkQ8Mjk52CukIxiwwCfVV5FD7gYil3eIG67Cgh14Hlt hnkAnRRggI9Eq13y9eWJYFNzSOMNX546 =5jSW -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 04, 2010 at 08:14:21PM -0500, Robert Bonomi wrote: > > From owner-freebsd-questi...@freebsd.org Sun Apr 4 17:14:17 2010 > > Date: Sun, 4 Apr 2010 15:13:49 -0700 > > From: Gary Kline > > To: "Randal L. Schwartz" , glar...@freebsd.org, > > FreeBSD Mailing List > > Cc: > > Subject: Re: perl qstn... > > > > On Sun, Apr 04, 2010 at 10:58:35AM -1000, p...@pair.com wrote: > > > in message <20100404203951.gb47...@thought.org>, > > > wrote Gary Kline thusly... > > > > > > > > ---Maybe you can clue me in on this one: around a dozen years ago > > > > i somw found a recursive grep named tgrep online. to save tying, > > > > i renamed it "rgr". i can start anywhere and 'rgr pattern' > > > > --WITHOUT ANY ASTERISK-- will find any pattern and skip binary or > > > > tarballs or compressed files. given this, rgr has become my > > > > favorite utility, but since it doesn't have All of grep's > > > > options, yes, it's tru e, there are times whrn i have to use the > > > > real thing. i have searched for tgrep and cannot find a newer > > > > more complete version. would you or anyone reading this know > > > > where an upgraded version is? > > > > > > > > Here is the Usage string: > > > > > > > > p4 13:07 [5524] rgr > > > > Usage: tgrep [-iredblLnf] regexp filepat ... > > > > tgrep -h for help [[ ... ]] > > Google to the rescue. Given the program name, and the author, one finds that > this code was in "UNIX Power Tools" (O'Reilly * Assoc.) > right; i've got the power tools book front and center. it must have come with tgrep on a floppy. -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.79a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Caution:: Off-topic Re: perl qstn...
On Sun, Apr 04, 2010 at 02:33:02PM -0700, Gary Kline wrote: > > anybody know if we need a new C [[maybe D]] that would be > allowed to grow? There's already a D. I don't really know much about it, though. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpluEACy1sZx.pgp Description: PGP signature
Re: perl qstn...
> From owner-freebsd-questi...@freebsd.org Sun Apr 4 17:14:17 2010 > Date: Sun, 4 Apr 2010 15:13:49 -0700 > From: Gary Kline > To: "Randal L. Schwartz" , glar...@freebsd.org, > FreeBSD Mailing List > Cc: > Subject: Re: perl qstn... > > On Sun, Apr 04, 2010 at 10:58:35AM -1000, p...@pair.com wrote: > > in message <20100404203951.gb47...@thought.org>, > > wrote Gary Kline thusly... > > > > > > ---Maybe you can clue me in on this one: around a dozen years ago > > > i somw found a recursive grep named tgrep online. to save tying, > > > i renamed it "rgr". i can start anywhere and 'rgr pattern' > > > --WITHOUT ANY ASTERISK-- will find any pattern and skip binary or > > > tarballs or compressed files. given this, rgr has become my > > > favorite utility, but since it doesn't have All of grep's > > > options, yes, it's tru e, there are times whrn i have to use the > > > real thing. i have searched for tgrep and cannot find a newer > > > more complete version. would you or anyone reading this know > > > where an upgraded version is? > > > > > > Here is the Usage string: > > > > > > p4 13:07 [5524] rgr > > > Usage: tgrep [-iredblLnf] regexp filepat ... > > > tgrep -h for help > > > > > > > > > if not for trgep/rgr my shoulder would've fallen off and just > > > laid on the floor; that's how much i use this script. having the > > > 'w' switch would be nice, so would the -N switch. > > > > What does "-N" do in grep included with FreeBSD? My version > > (FreeBSD 8) only has "-n". > > > Sorry, my bad. I should have said that "N" was any positive > integer. Sometimes I'll be searching for a phrase that i'm > not certain of and will type grep -7 PATTERN file[s] where > PATTERN is a known. I'll pipe around for various other > strings. > > > > I know of one tcgrep (by Tom Christiansen) ... > > > > http://www.perl.com/CPAN/authors/id/TOMC/scripts/tcgrep.gz > > > > > > Then, there is ack ... > > > > http://search.cpan.org/dist/ack/ack > > > > > > ... may need to tinker with option to search non-Perl files (see -a > > option). > > > > Or, simply ... > > > > #!/bin/sh > > > > # If your particular egrep is laced with potent PCRE, may use -P > > # option (before "$@") to specify Perl regex. > > egrep -r $@ . > > > > > this tgrep is from the NL; by a Prof Piet van Oostrum and is > dated 5/19/93. i think ii wrote this fellow many years ago. > Zip. I'll ck out ack when i'm using a gui mailer, thanks. Google to the rescue. Given the program name, and the author, one finds that this code was in "UNIX Power Tools" (O'Reilly * Assoc.) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: Caution:: Off-topic Re: perl qstn...
On Sun, Apr 4, 2010 at 11:33 PM, Gary Kline wrote: > Can C include the perl regex packages? Yes! Just use PCRE. Or, if you prefer C++, Boost.Regex: http://www.pcre.org/ http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/index.html -- Cordula's Web. http://www.cordula.ws/ ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 04, 2010 at 10:58:35AM -1000, p...@pair.com wrote: > in message <20100404203951.gb47...@thought.org>, > wrote Gary Kline thusly... > > > > ---Maybe you can clue me in on this one: around a dozen years ago > > i somw found a recursive grep named tgrep online. to save tying, > > i renamed it "rgr". i can start anywhere and 'rgr pattern' > > --WITHOUT ANY ASTERISK-- will find any pattern and skip binary or > > tarballs or compressed files. given this, rgr has become my > > favorite utility, but since it doesn't have All of grep's > > options, yes, it's tru e, there are times whrn i have to use the > > real thing. i have searched for tgrep and cannot find a newer > > more complete version. would you or anyone reading this know > > where an upgraded version is? > > > > Here is the Usage string: > > > > p4 13:07 [5524] rgr > > Usage: tgrep [-iredblLnf] regexp filepat ... > > tgrep -h for help > > > > > > if not for trgep/rgr my shoulder would've fallen off and just > > laid on the floor; that's how much i use this script. having the > > 'w' switch would be nice, so would the -N switch. > > What does "-N" do in grep included with FreeBSD? My version > (FreeBSD 8) only has "-n". Sorry, my bad. I should have said that "N" was any positive integer. Sometimes I'll be searching for a phrase that i'm not certain of and will type grep -7 PATTERN file[s] where PATTERN is a known. I'll pipe around for various other strings. > > I know of one tcgrep (by Tom Christiansen) ... > > http://www.perl.com/CPAN/authors/id/TOMC/scripts/tcgrep.gz > > > Then, there is ack ... > > http://search.cpan.org/dist/ack/ack > > > ... may need to tinker with option to search non-Perl files (see -a > option). > > Or, simply ... > > #!/bin/sh > > # If your particular egrep is laced with potent PCRE, may use -P > # option (before "$@") to specify Perl regex. > egrep -r $@ . > this tgrep is from the NL; by a Prof Piet van Oostrum and is dated 5/19/93. i think ii wrote this fellow many years ago. Zip. I'll ck out ack when i'm using a gui mailer, thanks. gary > > - parv > > -- > -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.79a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Caution:: Off-topic Re: perl qstn...
On Sun, Apr 04, 2010 at 12:45:30PM -0400, Alejandro Imass wrote: > On Sun, Apr 4, 2010 at 11:27 AM, Randal L. Schwartz > wrote: > >> "Randal" == Randal L Schwartz writes: > > > > Randal> Even simpler: > > > > Randal> if (@ARGV) { > did you mean unless? ;-) > > Randal> print "No args\n"; > > Randal> } else { > > Randal> print "arg is $ARGV[0]\n"; > > Randal> } > > > > Augh. I hit send just as I realized that's backwards. Need > > more caffiene. Swap the true and false blocks there. :) just having my 77th mug of french roast, so i'm hip. ...Anyway, here's one i'v been wanting to ask for years but don't know where to pose. Is C dead? i mean, since it's been "official" for years, can C add things like the unless keyword? Can C include the perl regex packages? if i asked this anywhere else, they would send out the men in white coats an d haul me away. here i'm safe:) anybody know if we need a new C [[maybe D]] that would be allowed to grow? gary > > > > -- > > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > > http://www.stonehenge.com/merlyn/> > > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion > > ___ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > > > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.79a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
in message <20100404203951.gb47...@thought.org>, wrote Gary Kline thusly... > > ---Maybe you can clue me in on this one: around a dozen years ago > i somw found a recursive grep named tgrep online. to save tying, > i renamed it "rgr". i can start anywhere and 'rgr pattern' > --WITHOUT ANY ASTERISK-- will find any pattern and skip binary or > tarballs or compressed files. given this, rgr has become my > favorite utility, but since it doesn't have All of grep's > options, yes, it's tru e, there are times whrn i have to use the > real thing. i have searched for tgrep and cannot find a newer > more complete version. would you or anyone reading this know > where an upgraded version is? > > Here is the Usage string: > > p4 13:07 [5524] rgr > Usage: tgrep [-iredblLnf] regexp filepat ... > tgrep -h for help > > > if not for trgep/rgr my shoulder would've fallen off and just > laid on the floor; that's how much i use this script. having the > 'w' switch would be nice, so would the -N switch. What does "-N" do in grep included with FreeBSD? My version (FreeBSD 8) only has "-n". I know of one tcgrep (by Tom Christiansen) ... http://www.perl.com/CPAN/authors/id/TOMC/scripts/tcgrep.gz Then, there is ack ... http://search.cpan.org/dist/ack/ack ... may need to tinker with option to search non-Perl files (see -a option). Or, simply ... #!/bin/sh # If your particular egrep is laced with potent PCRE, may use -P # option (before "$@") to specify Perl regex. egrep -r $@ . - parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 04, 2010 at 08:25:03AM -0700, Randal L. Schwartz wrote: > > "Gary" == Gary Kline writes: > > Gary> #!/usr/bin/perl > Gary> $argc = @ARGV; > Gary> if (! $argc ) { > Gary> printf("No args; need filename.\n"); > Gary> } > Gary> else { > Gary> printf("%s\n", @ARGV); > Gary> } > > Even simpler: > > if (@ARGV) { > print "No args\n"; > } else { > print "arg is $ARGV[0]\n"; > } > > If you're studying perl, you might want to join the very > beginner-friendly mailing list, info at > http://lists.perl.org/list/beginners.html, or start a conversation on > perlmonks.org, also relatively beginner-friendly. > > And I'd recommend a couple of good books, but I might be seen as > self-pimping. :) hey man, pimp away! we'll all learn a few tricks. ---i had to teach myself perl around '96 and bought a couple books, one with a floppy full of short programs. After doing a find . -name "*" -exec head -15 {} \; | more thru the truckload of these nifties, i finally came across the "$argc" idea. there are around a dozen no-longer-throwaways that need the kind of no-arg tip just to make the scripts more user friendly. even tho i'm the Only person who'll ever use them. ---Maybe you can clue me in on this one: around a dozen years ago i somw found a recursive grep named tgrep online. to save tying, i renamed it "rgr". i can start anywhere and 'rgr pattern' --WITHOUT ANY ASTERISK-- will find any pattern and skip binary or tarballs or compressed files. given this, rgr has become my favorite utility, but since it doesn't have All of grep's options, yes, it's tru e, there are times whrn i have to use the real thing. i have searched for tgrep and cannot find a newer more complete version. would you or anyone reading this know where an upgraded version is? Here is the Usage string: p4 13:07 [5524] rgr Usage: tgrep [-iredblLnf] regexp filepat ... tgrep -h for help if not for trgep/rgr my shoulder would've fallen off and just laid on the floor; that's how much i use this script. having the 'w' switch would be nice, so would the -N switch. > > But if you look at http://learn.perl.org/ you'll see a number of other > resources, including free tutorials online. tx for the pointer; i'll add it to my bookmarks. gary > > print "Just another Perl hacker,"; # the original > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > http://www.stonehenge.com/merlyn/> > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion -- Gary Kline kl...@thought.org http://www.thought.org Public Service Unix http://jottings.thought.org http://transfinite.thought.org The 7.79a release of Jottings: http://jottings.thought.org/index.php ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 4, 2010 at 11:25 AM, Randal L. Schwartz wrote: >> "Gary" == Gary Kline writes: [...] > And I'd recommend a couple of good books, but I might be seen as > self-pimping. :) > > But if you look at http://learn.perl.org/ you'll see a number of other > resources, including free tutorials online. > The "trilogy" is a must-have regardless if you are beginner intermediate or advanced, and regardless of who wrote them ;-) - Learning Perl - Intermediate Perl - Advanced Perl Programming Of course, the Camel book (Programming Perl), and Perl Best Practices which IMHO is a must read for _any_ language but especially for Perl hackers. More here: http://oreilly.com/pub/topic/perl Best, Alejandro Imass > print "Just another Perl hacker,"; # the original > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > http://www.stonehenge.com/merlyn/> > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 4, 2010 at 2:14 PM, Polytropon wrote: > On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin wrote: >> On Sun, Apr 04, 2010 at 12:45:30PM -0400, Alejandro Imass wrote: >> > did you mean unless? ;-) >> >> I find "if" to be clearer than "unless" when there's an "else", so >> instead of making that "if" into an "unless", I'd just swap the >> conditional actions. > > A quite language-independent technical sidenote :-) ... > > If your if() conditional is to test an exception, something > that you usually DON'T want to happen - i. e. missing command > line parameters - you can use the ! negation operator to > indicate this in the if() argument. > _precisely_ what unless is for. it's just a funny way of writing if(!... or should I say if(! is a funny way to write unless ;-) But honestly pun aside unless(){} is far more readable than if(!){} and _especially_ if you are programming in an exception manner as you correctly point out. Every language should have an unless construct. [...] > And you could even force perl to exit with an exit code != 0 > to indicate that something happened (e. g. program wasn't run > successfully). > a good practice in any language... > Now, as the "don't want case" has been considered, you can > easily continue with your program, no need to put it into > an else { } branch. > ahh! the clarity of unless > > > > PS. I'm not familiar with perl enough to be sure that the ! > operator can be used at @ARGV to make sure it's > 0, In "scalar context" will automagically return the number of elements perldoc perlintro (section Perl variable types) > and how or if to use exit() to set the return code. die "Bailing cause you forgot the filename" unless @ARGV Yes, that _is_ actual code :) Will not only die with a pretty message on STDERR but will return the value of $! (errno) as exit value. (no need to make up exit codes) Good thing we are on a FBSD list, because I can't see the sense of programming in a non-nix environment ;-) > I hardly can read perl at all, so the essence of my > examples is of a rather generic nature. :-) Look mommi! Reading Perl is just like reading plain english! (or in Nigerian spam for that matter http://search.cpan.org/~jwalt/Acme-Lingua-NIGERIAN-1.0.0/NIGERIAN.pm) Cheers, Alejandro Imass > > -- > Polytropon > Magdeburg, Germany > Happy FreeBSD user since 4.0 > Andra moi ennepe, Mousa, ... > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, 4 Apr 2010 10:33:53 -0600, Chad Perrin wrote: > On Sun, Apr 04, 2010 at 12:45:30PM -0400, Alejandro Imass wrote: > > did you mean unless? ;-) > > I find "if" to be clearer than "unless" when there's an "else", so > instead of making that "if" into an "unless", I'd just swap the > conditional actions. A quite language-independent technical sidenote :-) ... If your if() conditional is to test an exception, something that you usually DON'T want to happen - i. e. missing command line parameters - you can use the ! negation operator to indicate this in the if() argument. if(!...@argv) { print "No args\n"; exit; } In a short error message, you should indicate what you are expecting, e. g. with a synopsis or a simple example (no need for a 25 line help text here, e. g. print "Input file name is missing.\n"; print "usage: blabla.pl \n"; or print "Use: blabla.pl \n"; And you could even force perl to exit with an exit code != 0 to indicate that something happened (e. g. program wasn't run successfully). Now, as the "don't want case" has been considered, you can easily continue with your program, no need to put it into an else { } branch. PS. I'm not familiar with perl enough to be sure that the ! operator can be used at @ARGV to make sure it's > 0, and how or if to use exit() to set the return code. I hardly can read perl at all, so the essence of my examples is of a rather generic nature. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ... ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 4, 2010 at 11:04 AM, Chad Perrin wrote: > On Sun, Apr 04, 2010 at 08:25:03AM -0700, Randal L. Schwartz wrote: [...] > The final member of the traditional camelid trilogy, and a great book to Hmm, so there _are_ in fact several trilogies! I would swap the Camel for the Black Leopard anyday. Not implying that the author is not a great writer, but the Camel book is mostly a printout of perldoc perl sure hope Larry is not on this list > tack onto the list after the Alpaca, is the Camel Book, titled > Programming Perl. It's sorta the definitive reference for Perl > programmers, and covers a lot more of the language and its philosophy > than the Llama and Alpaca, though in my opinion the Llama and Alpaca > together provide a needed introduction that the Camel only skims past > (out of necessity, really, since a hand-holding introduction isn't really > the book's purpose). > > There's also Mastering Perl, which was written as a sequel to > Intermediate Perl, and I'm sure it's an excellent book. I haven't read > it, though, and know next to nothing about it, so I can't really > recommend it. > Perhaps the Vicuña and kids is in fact the thrid member of the "trilogy", but the Black Leopard is a must have to become a respected Perl hacker IMHO. Anyway, since this is all OT I started this thread in PM for your comments: http://www.perlmonks.org/?node_id=832725 Cheers, Alejandro Imass ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 04, 2010 at 12:45:30PM -0400, Alejandro Imass wrote: > On Sun, Apr 4, 2010 at 11:27 AM, Randal L. Schwartz > wrote: > >> "Randal" == Randal L Schwartz writes: > > > > Randal> Even simpler: > > > > Randal> if (@ARGV) { > did you mean unless? ;-) I find "if" to be clearer than "unless" when there's an "else", so instead of making that "if" into an "unless", I'd just swap the conditional actions. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpDO8HYcLtW7.pgp Description: PGP signature
Re: perl qstn...
On Sun, Apr 4, 2010 at 11:27 AM, Randal L. Schwartz wrote: >> "Randal" == Randal L Schwartz writes: > > Randal> Even simpler: > > Randal> if (@ARGV) { did you mean unless? ;-) > Randal> print "No args\n"; > Randal> } else { > Randal> print "arg is $ARGV[0]\n"; > Randal> } > > Augh. I hit send just as I realized that's backwards. Need > more caffiene. Swap the true and false blocks there. :) > > -- > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 > http://www.stonehenge.com/merlyn/> > Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. > See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion > ___ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org" > ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, Apr 04, 2010 at 08:25:03AM -0700, Randal L. Schwartz wrote: > > Even simpler: > > if (@ARGV) { > print "No args\n"; > } else { > print "arg is $ARGV[0]\n"; > } As Randal noted, he accidentally swapped the conditions here. Just for the sake of absolute clarity, I'll actually swap them: if (@ARGV) { print "arg is $ARGV[0]\n"; } else { print "no args\n"; } > > If you're studying perl, you might want to join the very > beginner-friendly mailing list, info at > http://lists.perl.org/list/beginners.html, or start a conversation on > perlmonks.org, also relatively beginner-friendly. PerlMonks in particular is an excellent resource. I haven't been active there recently, but when I have been active there, I've always found it rewarding and educational. I can't recommend it enough. > > And I'd recommend a couple of good books, but I might be seen as > self-pimping. :) That's okay. I'll pimp them for you. Learning Perl, also known as The Llama Book (because it has a llama on the cover), is one of the all-time best beginner's books for *any* language that I've ever encountered. I've gone through both the second and fourth editions, and both are excellent books. I prefer the organization of the second edition a bit, but the fourth is a trifle more up to date and does a much better job of covering Windows-related Perl development issues. If you're only worried about Unixy development and execution environments, my personal recommendation would be the second edition, though I suppose your mileage may vary. As a follow-up to the Llama, the Alpaca book (it has an alpaca on the cover, naturally) -- in its first edition known as Learning Perl Objects, References, and Modules (or Perl PORM, as I like to call it), and in later editions titled Intermediate Perl -- is also an excellent book. In addition to teaching more about Perl in particular, it also teaches some important general programming concepts from a Perl perspective, thus helping broaden your understanding of programming in general. The final member of the traditional camelid trilogy, and a great book to tack onto the list after the Alpaca, is the Camel Book, titled Programming Perl. It's sorta the definitive reference for Perl programmers, and covers a lot more of the language and its philosophy than the Llama and Alpaca, though in my opinion the Llama and Alpaca together provide a needed introduction that the Camel only skims past (out of necessity, really, since a hand-holding introduction isn't really the book's purpose). There's also Mastering Perl, which was written as a sequel to Intermediate Perl, and I'm sure it's an excellent book. I haven't read it, though, and know next to nothing about it, so I can't really recommend it. All four of the above are published by O'Reilly, and the three I've read at least are each the kind of book that has given O'Reilly its reputation as a purveyor of excellent technical books. Perl is blessed by an absurd number of excellent programming books by knowledgeable authors, and there are many more that are worth your time as well -- but in general the above are the canonical starting steps, with others following from there as you start figuring out what specific areas you want to give your focus next. Unfortunately, there are also a number of really crappy Perl books out there (many books that spell it PERL, in all-capital letters, are among the not-so-great books), and as such I figured I should be explicit in sharing my thoughts on the best books to get started in Perl. Now that I've gotten so far off-topic for this list, I'll return you to your regularly scheduled programming. > > But if you look at http://learn.perl.org/ you'll see a number of other > resources, including free tutorials online. > > print "Just another Perl hacker,"; # the original -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpTcet2ag6PP.pgp Description: PGP signature
Re: perl qstn...
> "Randal" == Randal L Schwartz writes: Randal> Even simpler: Randal> if (@ARGV) { Randal> print "No args\n"; Randal> } else { Randal> print "arg is $ARGV[0]\n"; Randal> } Augh. I hit send just as I realized that's backwards. Need more caffiene. Swap the true and false blocks there. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
> "Gary" == Gary Kline writes: Gary> #!/usr/bin/perl Gary> $argc = @ARGV; Gary> if (! $argc ) { Gary> printf("No args; need filename.\n"); Gary> } Gary> else { Gary> printf("%s\n", @ARGV); Gary> } Even simpler: if (@ARGV) { print "No args\n"; } else { print "arg is $ARGV[0]\n"; } If you're studying perl, you might want to join the very beginner-friendly mailing list, info at http://lists.perl.org/list/beginners.html, or start a conversation on perlmonks.org, also relatively beginner-friendly. And I'd recommend a couple of good books, but I might be seen as self-pimping. :) But if you look at http://learn.perl.org/ you'll see a number of other resources, including free tutorials online. print "Just another Perl hacker,"; # the original -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sun, 2010-04-04 at 00:07 -0400, Greg Larkin wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Gary Kline wrote: > > guys, > > > > i'm finally trying to get my private scripts and binaries in > > ~/bin in order. several of my perl scripts were meant to be > > throwaway ... but a few seem to be more useful and i would have > > to have informational or usage{} type messages. > > > > if a .pl script has to have at least one arg, is there an easy > > way to do that? can i have a perl fn called usage() that would > > be fed various strings? > > > > tia, > > > > gary > > > > > > > > Hi Gary, > > Check out this Perl module that builds on Getopt::Long, but also > includes support for echoing usage messages for each option: > http://search.cpan.org/~rjbs/Getopt-Long-Descriptive-0.085/lib/Getopt/Long/Descriptive.pm > > Hope that helps, > Greg thanks for your url as well and the others to posted. but it seems like overkill since i dont need any explicit option or argument. i just need the script to tell me whether i have an arg or not. following is something i've kept in one of my junk drawers from when i was learning to write bourne sscripts. it uses the "$[token]" syntax that determines whether there are Any args on the cmdline. if not, the script prints a message and exits. #!/bin/sh if [ $# -eq 0 ] then echo "No args; need filename." else echo "$1" fi After a couple hours experimentation, the following does the same for my perl scripts: #!/usr/bin/perl $argc = @ARGV; if (! $argc ) { printf("No args; need filename.\n"); } else { printf("%s\n", @ARGV); } gary ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Gary Kline wrote: > guys, > > i'm finally trying to get my private scripts and binaries in > ~/bin in order. several of my perl scripts were meant to be > throwaway ... but a few seem to be more useful and i would have > to have informational or usage{} type messages. > > if a .pl script has to have at least one arg, is there an easy > way to do that? can i have a perl fn called usage() that would > be fed various strings? > > tia, > > gary > > > Hi Gary, Check out this Perl module that builds on Getopt::Long, but also includes support for echoing usage messages for each option: http://search.cpan.org/~rjbs/Getopt-Long-Descriptive-0.085/lib/Getopt/Long/Descriptive.pm Hope that helps, Greg -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAku4EIoACgkQ0sRouByUApCXNgCgrLt1v3rV2+AjfxXMT1ew3GhE pZIAn0P5O7L5koQflkiQOuoTA+75POOe =Cyq4 -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
Re: perl qstn...
On Sat, Apr 03, 2010 at 02:17:06PM -0700, Randal L. Schwartz wrote: > > "Gary" == Gary Kline writes: > > Gary> if a .pl script has to have at least one arg, is there an easy > Gary> way to do that? > > Dare I say, "there's more than one way to do it?" :) > > See the "Getopt::" family in the CPAN. > > My favorite is Getopt::Long. For simple scripts I tend to use Getopt::Std instead, but Getopt::Long is great too. These two are pretty much the "standard" for command line option handling and help message generation in Perl. -- Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] pgpwV1YQ4xsBV.pgp Description: PGP signature
Re: perl qstn...
> "Gary" == Gary Kline writes: Gary> if a .pl script has to have at least one arg, is there an easy Gary> way to do that? Dare I say, "there's more than one way to do it?" :) See the "Getopt::" family in the CPAN. My favorite is Getopt::Long. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"