Re: sorting pathnames by basename
In a message dated: Wed, 21 Aug 2002 21:15:42 EDT [EMAIL PROTECTED] said: > (Yes, Derek, this is not immediately obvious. ;-) Well, yeah, but it's no different than some one trying to do 'man $SHELL' to find out what the bash $SHELL variable does. At some point you need to 'man man', so why not 'perldoc perldoc' :) -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Wed, 21 Aug 2002 19:52:12 EDT mike ledoux said: >On Tue, Aug 20, 2002 at 11:01:01AM -0400, [EMAIL PROTECTED] wrote: >> >> Well, I think it's more that they're lazy. Why type $OUTPUT_AUTOFLUSH >> when you can type $| instead? If someone who doesn't know the >> language needs to know what $| does, it's well documented. > >I see this sort of claim fairly frequently from the Perl crowd, usually >accompanied by 'everything you need to know is in perldoc'. Yet every >time I need to figure out what one of these obscure no-letter variables >does, perldoc falls down: > > mwl@voyager:~>perldoc '$|' > No documentation found for "$|". That's because you're not using perldoc correctly. Do perldoc perldoc for proper usage, for the magic vars use 'perldoc perlvar'. A complete list of the "perldocs" is available using 'perldoc perl'. -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
mike ledoux <[EMAIL PROTECTED]> writes: > Now, if I've got time to vgrep some dead tree, and access to one of the > O'Reilly Perl books, I can probably find what I'm looking for, but that > often isn't the case. I use perldoc (electronic) and Johan Vromans Perl 5 Pocket Reference (dead-tree -- very small) extensively. Regards, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
mike ledoux <[EMAIL PROTECTED]> writes: > I see this sort of claim fairly frequently from the Perl crowd, usually > accompanied by 'everything you need to know is in perldoc'. Yet every > time I need to figure out what one of these obscure no-letter variables > does, perldoc falls down: > > mwl@voyager:~>perldoc '$|' > No documentation found for "$|". perldoc gives you documentations for perl modules. "$|" is not a module. These variables are documented in the man pages: jabr@vishnu:~ $ man perl PERL(1) Perl Programmers Reference Guide PERL(1) NAME perl - Practical Extraction and Report Language For ease of access, the Perl manual has been split up into several sections: perlPerl overview (this section) perlfaq Perl frequently asked questions perlvar Perl predefined variables jabr@vishnu:~ $ man perlvar PERLVAR(1) Perl Programmers Reference Guide PERLVAR(1) NAME perlvar - Perl predefined variables DESCRIPTION Predefined Names The following names have special meaning to Perl. Most punctuation names have reasonable mnemonics, or analogs in the shells. Nevertheless, if you wish to use long vari- able names, you need only say use English; at the top of your program. This will alias all the short names to the long names in the current package. Some even autoflush HANDLE EXPR $OUTPUT_AUTOFLUSH $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; "$|" tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See the getc entry in the perlfunc manpage for that. (Mnemonic: when you want your pipes to be piping hot.) -- John Abreau / Executive Director, Boston Linux & Unix ICQ 28611923 / AIM abreauj / JABBER [EMAIL PROTECTED] / YAHOO abreauj Email [EMAIL PROTECTED] / WWW http://www.abreau.net / PGP-Key-ID 0xD5C7B5D9 PGP-Key-Fingerprint 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99 Some people say, "The enemy of my enemy is my friend." I often respond, "When elephants fight, it's the grass that gets trampled." msg00420/pgp0.pgp Description: PGP signature
Re: sorting pathnames by basename
On Wednesday, August 21, 2002, at 07:52 PM, mike ledoux wrote: > So, if I'm in a rush (usually), and I need to figure out what someone > else's unreadable Perl does, where should I be looking? I'm too lazy to lift my hands off my keyboard or mouse, to the shelf right in front of my face where "Programming Perl" rests, and look up the variables. I usually just head over to http://perldoc.com/ and read the man pages there. For some reason it's just more legible when presented as a web page than as a man page in a terminal window. (Must be the whitespace.) I've bookmarked http://perldoc.com/perl5.6.1/pod/perl.html for easy access. Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Wed, 21 Aug 2002, at 7:52pm, mike ledoux wrote: > So, if I'm in a rush (usually), and I need to figure out what someone > else's unreadable Perl does, where should I be looking? For variables, try 'man perlvar' (or 'perldoc perlvar', if you prefer). Another very useful reference is 'man perlre' (for regular expressions). There are a whole bunch more. 'man perl' will give you a nice list of topics, and 'man perltoc' will give you a grep'able keyword index. (Yes, Derek, this is not immediately obvious. ;-) HTH! -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Mon, Aug 19, 2002 at 05:31:14PM -0400, Kevin D. Clark <[EMAIL PROTECTED]> wrote: > You have a list of stuff that you want sorted. The problem is is that > you want your stuff sorted according to a field contained in the input > (the last field). Further complicating matters is the fact that this > field is located at a non-constant place in the input field. I was thinking that `sort -t / -k -1` would be really cool here, but sort can't sense of a negative column index. I wonder is the FSF would accept such a patch to GNU sort? > The solution: take the input, generate a list from each line, each > element in the list consists of a tuple consisting of the original > line plus the comparison key. Sort the tuple-list using the > comparison key, and then after the sort is done, strip off all of the > comparison keys, returning the original list ({sans} tuples), sorted. > > This is actually a well-known technique in Perl, called the > Schwartzian Transform. Look it up on the web -- there are plenty of > good descriptions of it. That is basically what my example did, but continuing to use sed and sort instead of perl (for no particular reason -- I could come up with rationales but they may not be applicable). My suggestion took the filename, prepended it so sort could get at it, sorted the data by the first column only, and then removed that column. Since I don't see my post for some reason, I'll repeat it here: sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;' Since this is mildly different, and I've never heard of the Schwartzian Transform, I'm going to propose calling this Bell's Method. :-) -- Bob Bell <[EMAIL PROTECTED]> - "The greatest wage gains between 1997 and last year (1998) were reported by people working with Linux, a free operating system. Their knowledge of this increasingly popular system puts them in high demand for Internet projects..." -- http://detnews.com/1999/technology/9901/08/01080223.htm ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Bob Bell <[EMAIL PROTECTED]> writes: > Fix your box :-) Point taken, although I try to write portable code, and as such, I will always be a little bit conservative when I am using sed. > > 2: Those options to sort don't work on my Linux box. > > Really? They work on mine. What `sort` do you have? Mine's from > a textutils-2.0e-8 RPM. All options I used are part of UNIX 98 > (http://www.opengroup.org/onlinepubs/007908799/xcu/sort.html). $ rpm -q -f /bin/sort textutils-2.0.21-1 > > Still, I see where you're going here. How about this? > > > > sed -e 's;\(.*\)/\([^/]*\)$;\2/\1/\2;' | sort -t / +0 | sed 's;[^/]*/;;' > > > > This works on the various Unix boxen that I have at my disposal. > > Nope, you've just forced the pathname to contain a '/'. But here's > a simplified version that I think will work around your issues for > non-UNIX 98 compliant machines: > > sed -e 's;\(.*/\)*\(.*\);\2/\1\2;' | sort -f -d -t / +0 | sed -e 's;[^/]*/;;' My example, derived from yours, seems to work, as well as your new solution. Regards, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
The complexity of a computer language can result in the use of language subsets. Specifically, if the language has too many features, programmers will only learn a subset and since different programmers will learn different subsets, it becomes difficult for language implementors to guarantee that the language will be consistent across implementations. Niklaus Wirth, the designer of Pascal, operated under the philosophy that computer languages should be no more complicated than necessary. Later iterations of Pascal such as Modula 2 and Oberon (and their variations) were made succesively simpler in order to allow the programmer to accomplish his programming goals while at the same time allowing those that needed to read these programs to be able to clearly understand them (based on simplified syntax and a smaller number of reserved words). The Oberon language grammer fits nicely on a double sided 8x10 sheet of paper. The entire language report only occupies around 20 pages. See the language report at: http://www.oberon.ethz.ch/oreport.html and take note of the quote from A. Einstein ;^) -Alex P.S. Specific languages that have been described as too complex - PL/I, Ada, C++... - Original Message - From: "Erik Price" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, August 21, 2002 1:32 AM Subject: Re: sorting pathnames by basename > > On Tuesday, August 20, 2002, at 08:28 PM, [EMAIL PROTECTED] wrote: > > > All three mean the same thing, but the first is by far the most > > common in > > American English. Perl is a lot like English. > > I couldn't agree more. Here's why: > > English is supposedly the hardest language in the world to learn. Why? > Because there are so many ways to say the same thing! Yes, that is the > reason AFAIK. I'm not just talking about synonyms, I'm talking about > the way you can structure the grammar of the language to mean the same > thing, but in so many ways. > > I studied Japanese for years when I was in college, almost > double-majoring with it but not quite. And I was struck by how > systematic that language is. Sure, a lot of people will naturally > wonder if it's very hard, since there is a complex writing system based > on Chinese that consists of tens of thousands of characters (the > Kanji). But as far as learning the core, the very grammar of the > language itself, it is amazingly straightforward! Although there is > "more than one way to do it", this generally has more to do with slang > and formality than with the way that the language is structured. > > Perl is definitely English-like in this regard. > > > > > > Erik > > > > > > -- > Erik Price > > email: [EMAIL PROTECTED] > jabber: [EMAIL PROTECTED] > > ___ > gnhlug-discuss mailing list > [EMAIL PROTECTED] > http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss > ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On 21 Aug 2002, at 8:52am, Kevin D. Clark wrote: >> ... sort -fdt/k1 ... > > ... Those options to sort don't work on my Linux box ... I assume you mean the -k switch? On my RHL 7.3 box, which has GNU sort from GNU textutils 2.0.21, the "info" manual for "sort" states: > Warning: the `+POS1' usage is obsolescent. Future versions of > POSIX will require that support for it be withdrawn. Use `--key' > (`-k') instead. Just FYI. -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Wed, Aug 21, 2002 at 08:52:14AM -0400, Kevin D. Clark <[EMAIL PROTECTED]> wrote: > Bob Bell <[EMAIL PROTECTED]> writes: > > sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;' > > This doesn't work for me for a number of reasons: > > 1: sed is known to contain a number of bugs, and you're hitting one > of them on my SVR4-derived Solaris box. That first call to sed > doesn't yield any changes. Well, I can't be responsible for broken Unixen, now, can I? Fix your box :-) > 2: Those options to sort don't work on my Linux box. Really? They work on mine. What `sort` do you have? Mine's from a textutils-2.0e-8 RPM. All options I used are part of UNIX 98 (http://www.opengroup.org/onlinepubs/007908799/xcu/sort.html). > Still, I see where you're going here. How about this? > > sed -e 's;\(.*\)/\([^/]*\)$;\2/\1/\2;' | sort -t / +0 | sed 's;[^/]*/;;' > > This works on the various Unix boxen that I have at my disposal. Nope, you've just forced the pathname to contain a '/'. But here's a simplified version that I think will work around your issues for non-UNIX 98 compliant machines: sed -e 's;\(.*/\)*\(.*\);\2/\1\2;' | sort -f -d -t / +0 | sed -e 's;[^/]*/;;' If '-f' and '-d' are problems, you could just drop them. I used them because they were in the original suggestion, so I figure MOD wanted to use them in the comparison. -- Bob Bell <[EMAIL PROTECTED]> - "Beware of the above code; I have only proved it correct, not tried it." -- Donald Knuth, famous computer scientist ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Bob Bell <[EMAIL PROTECTED]> writes: > '/' is an illegal character in a filename, right? > > sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;' This doesn't work for me for a number of reasons: 1: sed is known to contain a number of bugs, and you're hitting one of them on my SVR4-derived Solaris box. That first call to sed doesn't yield any changes. 2: Those options to sort don't work on my Linux box. Still, I see where you're going here. How about this? sed -e 's;\(.*\)/\([^/]*\)$;\2/\1/\2;' | sort -t / +0 | sed 's;[^/]*/;;' This works on the various Unix boxen that I have at my disposal. Regards, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Tuesday, August 20, 2002, at 08:28 PM, [EMAIL PROTECTED] wrote: > All three mean the same thing, but the first is by far the most > common in > American English. Perl is a lot like English. I couldn't agree more. Here's why: English is supposedly the hardest language in the world to learn. Why? Because there are so many ways to say the same thing! Yes, that is the reason AFAIK. I'm not just talking about synonyms, I'm talking about the way you can structure the grammar of the language to mean the same thing, but in so many ways. I studied Japanese for years when I was in college, almost double-majoring with it but not quite. And I was struck by how systematic that language is. Sure, a lot of people will naturally wonder if it's very hard, since there is a complex writing system based on Chinese that consists of tens of thousands of characters (the Kanji). But as far as learning the core, the very grammar of the language itself, it is amazingly straightforward! Although there is "more than one way to do it", this generally has more to do with slang and formality than with the way that the language is structured. Perl is definitely English-like in this regard. Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Mon, Aug 19, 2002 at 03:46:40PM -0400, Michael O'Donnell <[EMAIL PROTECTED]> wrote: > > Given a list of pathnames, I'd like to be able to > sort that list by the basename of each file in the > list, ie. the pathname > >q/r/s/t/u/v/aaa > > ...would sort ahead of > >//bbb > > ...because the basename 'aaa' sorts lexicographically > ahead of 'bbb'. > > My current approach is a bit clunky but works as long as > the pathnames in question contain no spaces, thus: > >sed -e 's;/\([^/]*\)$; \1;' | sort -bfd +1 | sed -e 's; ;/;' > > ...which replaces the last slash in each pathname with > a space, sorts that list of dual-field space-delimited > records keyed on the second field, and then replaces > the slashes. Suggestions for improvement welcome. '/' is an illegal character in a filename, right? sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;' -- Bob Bell <[EMAIL PROTECTED]> - "Digital files cannot be made uncopyable, any more than water can be made not wet." -- Bruce Schneier, CRYPTO-GRAM, May 15, 2001 ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Python (was: sorting pathnames by basename)
On Tue, 20 Aug 2002, at 9:54am, [EMAIL PROTECTED] wrote: > Is Python also a "text-munging" type language aimed at sysadmin type > problems? Was it too, specifically designed to pick up where awk and sed > fell short? I know nothing about the Python language, but I do know a tiny bit about the design goals behind it (which I got mainly from discussions with Python fans). I would say the single biggest design goal of Python is elegance, in the Jargon File sense [1]. Take the quote "A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away.", apply it to a programming language, and you get Python. Other design goals include pervasive object-orientedness, a clean -- even sparse -- syntax, and interactive, dynamic operation. Python is not specialized for text munching the way Perl is. As I understand it, much of the functionality of Perl's text processing is available as standard library modules in Python, but the language itself is no more suited to that than it is to anything else. Myself, I would love to attend more LUG meetings about Python. [1] http://www.tuxedo.org/~esr/jargon/html/entry/elegant.html -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Tue, 20 Aug 2002, at 12:30pm, Erik Price wrote: > For that matter, I find that the word "cannonical" is bandied about in > Perl culture far more than anywhere else! ;) Interesting for a language > in which there's more than one way to do things. I suspect that is why. If there are many ways to do things, the community will likely want to settle on a subset of them. Hence the term "idiom", which also gets a lot of use in Perl. Consider these three English sentences: - That is Fred's pencil. - That pencil belongs to Fred. - That is the pencil of Fred. All three mean the same thing, but the first is by far the most common in American English. Perl is a lot like English. (Hmmm, that could be considered an insult to Perl. ) -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Tue, 2002-08-20 at 11:57, Erik Price wrote: > Actually, I tried to write it more densely but couldn't. I'm not a > Python guru by any stretch, but I had thought that I could use "for key > in sorted.sort()" instead of having the sort() method call on a separate > line. Apparently I can't. Nope - you can't. A call to the sort method doesn't return another list, nor even a reference to the list. In fact, what it does return is a "None" object that python uses rather than "Null". -- "Ha ha - you may be right, but remember! You are also flammable..." -Donald, one of my psycho cousins Cole Tuininga Lead Developer Code Energy, Inc [EMAIL PROTECTED] PGP Key ID: 0x43E5755D ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Erik Price <[EMAIL PROTECTED]> writes: > For that matter, I find that the word "cannonical" is bandied about in > Perl culture far more than anywhere else! ;) Interesting for a > language in which there's more than one way to do things. Well, I just used the word canonical in the canonical way... (-: --kevin -- ``Bob just used `canonical' in the canonical way.'' -- GLS ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Tuesday, August 20, 2002, at 08:07 AM, Kevin D. Clark wrote: > In fact, my one-liner is probably the cannonical way that an > experienced Perl programmer would have solved that problem (or, at > least, pretty close). For that matter, I find that the word "cannonical" is bandied about in Perl culture far more than anywhere else! ;) Interesting for a language in which there's more than one way to do things. (Programming Perl defines that word in its glossary as "Reduced to a standard form to facilitate comparison.") -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: Programming [was Re: sorting pathnames by basename ]
On Tuesday, August 20, 2002, at 12:00 PM, [EMAIL PROTECTED] wrote: >> But at the point where I say to myself, "I really think that I could >> write this better and more easily if I used an object-oriented >> methodology and designed some class definitions to help me", I would >> turn to Python and not look back. > > Not knowing much about OO technique and/or methodology other than > what I've learned from Perl's bastardized attempt to rivet OO onto > the backside of a language never meant for OO programming, I have to > ask, is there a good, general, non-language specific text about OO > design and/or methodology around? > > I'd like to understand the concepts and terminology used in OO > programming before delving into something like Java or Python so that > I can take better advantage of the OO features of these languages, > but everything I've seen seems very language specific. There is a book written just for you, and it is excellent: "Beginning Java Objects", by Jacquie Barker (Wrox). This book tends to be a bit pedantic (I think it is written for CS 100 students), often taking a few pages to explain some things that are more briefly explained in Bruce Eckels' "Thinking in Java" (Prentice Hall). But that is its only drawback, and I actually would rather have more information than I need than less. The book is divided into thirds: 1. The fundamentals and concepts of object oriented programming 2. Object modelling -- turning real life situations into abstract object-based representations 3. Case study -- putting the fundamentals and concepts together to write a full program in Java The book advertises that it does not emphasize one language over others for the most part, and this is entirely correct. While it says "Java" on the cover, that's obviously for marketing reasons, because you can get through the first two thirds of this book using Python, Java, or even PHP. I think you can use Perl too, though OO in Perl is something that I am still very very new to. (The last third of the book is applying the code in Java, so yes it does focus on Java.) The point is that it teaches the basics of OO programming and design, and not how to write in Java. This book should really be called "Beginning Object Oriented Programming and Design for any language, with examples in Java". And I bet that if Python had *half* the mindshare that Java has, Barker would have written the book to use Python instead. Erik PS: I am still reading Bruce Eckel's book "Thinking in Java" and teaching myself Java, and already I am very glad that I read the first 2/3 of Jacquie Barker's book first. Eckel's book is good, but races through the fundamentals. Barker's book shines when it comes to fundamentals. -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Paul, No, I wouldn't say that Python quite fills the same nitch. It does have serious text processing capability, but you will type a fair amount more to do those kinds of jobs in Pyhton. Also, www.python.org has (or had, I haven't looked lately) some performance comparisons with other means of doing stuff, and IIRC Perl also usually came out a tad faster (but that may have been version dependent). But any performance difference isn't due to the extra verbiage, since both internalize things before execution (unlike tcl). On the other hand, I've found that if I don't use Perl much, (I have tried to "learn" to use it effectively), the syntax and feature set seems to drift away from me. Python is easier for me to go back to, even if I've been spending my time in PIC or Scenix assembler, or running the NC drill machine. Years of programming with C, starting with Fortran over 30 years ago, etc., may make Python more comfortable to me, but I think that it's more than that. I think that it really is easier to get you mind around. Python also serves me well as a rapid development language for things that may become C or C++ projects. Since I have been able to do my text processing conveniently with it, it makes sense for me to choose not to bother getting good at another quite different language like Perl. I'm not saying that there's anything wrong with Perl, just that it's not the only choice. Mike O'Donnell apparently also doesn't fine Perl syntax agreeable, so it seems to me that I was correct to suggest the alternative. Since I don't know Perl well, I can't offer a reliable feature comparison. I believe that there is such on the web site. I suspect that pretty much all the features you need are in Python, although some of them will be implemented as functions or classes from a library, and even if they're built into the C source for the interpreter, they may syntacticly look like library functions (such as the basename function from the os package that Erik used). And, as with Perl, there are usually several ways to skin a cat. Erik used a dictionary (equivelent of the awk/perl associative array) to map back from his sort keys to the original lines, since it was the list (more like a regular array) of keys that got sorted. I'd been thinking more of using the string and perhaps regular expression stuff to convert the lines so that the basename part became "high order", sort, and convert back. I hope that I haven't rambled too much. Bill ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Programming [was Re: sorting pathnames by basename ]
In a message dated: Tue, 20 Aug 2002 11:57:55 EDT Erik Price said: >But at the point where I say to myself, "I really think that I could >write this better and more easily if I used an object-oriented >methodology and designed some class definitions to help me", I would >turn to Python and not look back. Not knowing much about OO technique and/or methodology other than what I've learned from Perl's bastardized attempt to rivet OO onto the backside of a language never meant for OO programming, I have to ask, is there a good, general, non-language specific text about OO design and/or methodology around? I'd like to understand the concepts and terminology used in OO programming before delving into something like Java or Python so that I can take better advantage of the OO features of these languages, but everything I've seen seems very language specific. Thanks, -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
I respond to Michael O'Donnell, Kevin Clark, Ben Scott, and [EMAIL PROTECTED] in this response: Michael O'Donnell wrote: > Wow. That doesn't suck. Thanks! Well, I wrote it in a text editor called BBEdit on Mac OS X. BBEdit's advert blurb is, literally: "It doesn't suck" (http://barebones.com/). Which I agree with wholeheartedly, it is my favorite programming environment. Kevin Clark wrote: > One-liners are not representitive of the readability of Perl code. I > hope you agree. Definitely. Perhaps those who are new to Perl don't quite see it yet (although I admit that I am still new to Perl), but I find that the one-liners are very elegant and spare me the bother of dropping into an editor for something so simple. Like writing some bash code right there on the command line. For that matter, I have to defer to Kevin's one-liner as it was definitely more elegant than the Python code. I only posted it because he asked for it! Kevin Clark also wrote: > Can any of the Python programmers on this list implement this as a > one-liner? Just wondering. > > (with Python's indentation rules, I think that this would be difficult) It's antithetical to the Python Way. JAPHs like elegant and terse one-liners, but Pythoneers generally don't or can't use them. Larry Wall wrote Perl so that there is more than one way to do everything, including coding style (use strict or english, etc). Python's philosophy is "there should generally be one obvious way to do something" even if that isn't the most efficient-looking code. Kevin Clark finally added: > OBTW, while I appreciate Erik's effort (because, in fact, I am > learning Python), in actuality, I believe that his program contains a > bug Good point! That Python script was a "five-minuter". If I had written it properly, it should have taken this into account, and also been written as a module so that it could itself be reimplemented in other code later ("import basenamesort.py"). Also, instead of being limited to just a filter for standard input, it would also have had the ability to be executed directly as a standalone program, perhaps with an argument passed to it ("filenames.txt" or something). That would have made it a "proper" modular Python script, but I fell asleep during "Clash of the Titans" at a friends' house a short while before , and I just wanted to check/respond to email before I went to bed. Of course a Python script could be written to accommodate these extra functions. Ben Scott wrote: > Without even knowing anything about Python, > I suspect that code could be made denser, by eliminating temporary > variables > and nesting things instead. Actually, I tried to write it more densely but couldn't. I'm not a Python guru by any stretch, but I had thought that I could use "for key in sorted.sort()" instead of having the sort() method call on a separate line. Apparently I can't. I've been spending a LOT more time learning Perl than Python, lately (b/c I'm unemployed and there are dozens more Perl jobs than Python jobs out there right now). Ben Scott also wrote: > This is an accident. In general, Perl was not designed -- it evolved. > It started small, and then creeping featurism ran rampant on it. Much > like > Unix, there are a great many things in Perl that don't make a lot of > sense > unless you know the history behind them. That's right! Don't forget that Perl 6 is (supposed to be) completely redesigned from scratch for this very reason. [EMAIL PROTECTED] wrote: > Is Python also a "text-munging" type language aimed at sysadmin type > problems? Was it too, specifically designed to pick up where awk > and sed fell short? Guido van Rossum originally wrote the language specifically for educational purposes, because of all of the shortcomings of BASIC. He wanted a fully object-oriented language that be difficult for programmers to develop bad habits from (note the lack of a GOTO, and the strict enforcement of whitespace and indenting). This is why Python has a nice interactive interpreter -- for real-time experimentation. Of course, programmers like the interactive interpreter because they can whip up a function or class definition and then play with it to see how it interacts with their code without having to execute an entire script, getting immediate feedback on their work. While I have seen some system-administration stuff written in Python, there isn't much. For one, Perl is far more widely-used and installed on more systems. Also, if I had to do extensive text munging, there is no question that I would use Perl to do it over Python unless I had some compelling reason not to. (This is just my opinion, but) Perl's text-munging abilities are more convenient to use than Python's. It's like, they're built into the syntax and mentality of Perl, whereas with Python you will probably end up importing a module like the string module and then executing various met
Re: sorting pathnames by basename
On Tue, 20 Aug 2002, at 10:45am, Derek D. Martin wrote: > Programming Perl seems to almost, but not quite recognize how painful > these things are to learn, by offering mnemonic devicess for each of > them. use English; That is not just an idle comment; it refers to the fact that Perl does recognize that these variables *are* cryptic, and provides a mechanism to As for why many people still use the funny-character variables: It is partly because 'use English' carries a performance penalty for some implementations, but mostly because the funny-character variables came first. > Here are two ways to do (more or less) the same thing, one in C and one in > Perl: > > setlinebuf( file ); > $| = 1; Here are two days to do (more or less) the same thing, one on Unix and one on MS-Windows: findstr foo myfile.txt grep foo myfile.txt Without knowing either of the two OSes, which is more self-documenting? Which is more obscure? > Well, there are certainly people who like to write obscure C as well. It > just seems to be part of the Perl culture... I've seen far less readable > Perl than C. I think a large part of Perl's reputation for being line noise is that Perl makes heavy use of regular expressions, which *do* look like line noise. Fortunately, however, Perl provides a mechanism for that, too, and is the only languages I know of that does -- the /x modifier allows one to embed whitespace and comments in a regular expression. -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Mon, 19 Aug 2002, at 7:18pm, Derek D. Martin wrote: > Perl seems to have gone out of its way to work like other common Unix > tools/languages (shell scripting, C, sed/grep), in others it seems to go > out of its way to do things in such a way as to be as confusing as > possible. How is that different from any other language? Most languages borrow from other languages, and yet still do things their own way. Compare C++, Java, and C#, for example. > An example of this would be the equivalent of a structure in C (or Pascal > or whatever). This is an accident. In general, Perl was not designed -- it evolved. It started small, and then creeping featurism ran rampant on it. Much like Unix, there are a great many things in Perl that don't make a lot of sense unless you know the history behind them. > The people who like to program Perl seem to have a propensity to prefer to > write code which takes advantage of all the obscure features, and > generally to write code which is unreadable. I think you put far too much weight on the "recreational hackers" who favor neat tricks. It is one thing to fire off one-liners because one can; it is quite another to do so in "real life". It is quite possible to write professional-quality, well-documented, non-obscure Perl code. The fact that some people take pleasure from not doing so does not make Perl a bad language. And while it does seem like the Perl community has a large percentage of people who like recreational hacking, I think that just reflects Perl's roots as a language that was evolved through usage. -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Tue, 20 Aug 2002 10:55:00 EDT "Hewitt Tech" said: >P.S. For many programmers, it's the language they use every day that they >favor. What is obscure for the neophyte is business as usual for the >experienced programmer in that language. Exactly the point I was trying to make! Thank you! -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Tue, 20 Aug 2002 10:45:48 EDT "Derek D. Martin" said: >Here are two ways to do (more or less) the same thing, one in C and >one in Perl: > > setlinebuf( file ); > $| = 1; > >Which is clearer to the inexperienced reader (but experienced >programmer)? Which is easier to remember, for the average person? >There is nothing to $| to attach any meaning to it... Hmmm, if you don't like $|, as Kevin already pointed out, you can: Use English; $OUTPUT_AUTOFLUSH = 1; which I actually find far more readable and understandable than even your C example above. >Programming Perl seems to almost, but not quite recognize how painful >these things are to learn, by offering mnemonic devicess for each of >them. But Perl hackers seem to favor this kind of variable, using >them often when there's no need to. Well, I think it's more that they're lazy. Why type $OUTPUT_AUTOFLUSH when you can type $| instead? If someone who doesn't know the language needs to know what $| does, it's well documented. (Personally, I always try to accompany these types with a comment that explains what these types of args do. The exceptions being $_ and $!, since they're used so often as a Perl programmer, you should know what those are.) >Again, it's not about documentation. It's about design. Right, and perl was designed to be as flexible or as rigid as you'd like it to be. I think it's more about learning the language. I "know" C, but I'm not proficient at it. I can write small programs, and do a little damage. But if I were to look at code written by others on this list who are more proficient, I'd be lost. The same goes for Perl. I've been writing perl for 8+ years, which makes me far more proficient at it than I am in any other language. I would say that you're quite a bit more proficient at C than I am, but less so at Perl. Things like $_, $!, $|, etc. are second nature to me, where as things like setlinebuf are second nature to you. The better you know a language, the less obscure it seems. Perl seems very obscure to those who don't know the language just as C seems quite obscure to those who don't know it. >> Example? > >Structures come to mind, though they're not as bad as some things I've >come across (can't recall what though). I thought I already gave >that, but I guess I didn't. Perl doesn't have structures, it has hashes. Different concept. They can be used to emulate a structure, but they are not structures. >Well, there are certainly people who like to write obscure C as well. >It just seems to be part of the Perl culture... I've seen far less >readable Perl than C. In fact, I'd say the most readable Perl I've >seen was in Learning Perl, and some of that I thought looked kinda >gross too. It is as if unreadability was designed into the language. I guess it's all perspective. I look at the code in Learning Perl, and I see very clear and obvious code. -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
I kind of like Eric Raymond's take on the various programming languages generally available on UNIX platforms. Take a look at: http://www.tuxedo.org/~esr/writings/taoup/chapter3.html -Alex P.S. For many programmers, it's the language they use every day that they favor. What is obscure for the neophyte is business as usual for the experienced programmer in that language. ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 At some point hitherto, [EMAIL PROTECTED] hath spake thusly: > >1. Perl seems to favor supporting a variety of features with obscure, > >meaningless, two-character variables that might be clearer with flags > >or arguments to functions that make use of it. > > Define obscure please. Try m-w.com. :) Or, I'll save you the trouble: 1 a : DARK, DIM b : shrouded in or hidden by darkness c : not clearly seen or easily distinguished : FAINT 2 : not readily understood or clearly expressed; also : MYSTERIOUS While definition 1 amuses me the most, definition 2 is what I'm talking about. It's not that the meaning isn't documented; it's that it's not clear from the reading, and memorizing the meanings of a couple of dozen two-character variables, particularly for use with a language which touts having no artificial limits, seems backward and archaic. Here are two ways to do (more or less) the same thing, one in C and one in Perl: setlinebuf( file ); $| = 1; Which is clearer to the inexperienced reader (but experienced programmer)? Which is easier to remember, for the average person? There is nothing to $| to attach any meaning to it... Programming Perl seems to almost, but not quite recognize how painful these things are to learn, by offering mnemonic devicess for each of them. But Perl hackers seem to favor this kind of variable, using them often when there's no need to. > Everything in the perl language is tediously and breathtakingly > documented and quickly accessible to any system on which perl has > been installed using either the 'man' or 'perldoc' commands. Again, it's not about documentation. It's about design. > >Whereas in many ways, Perl seems to have gone > >out of its way to work like other common Unix tools/languages (shell > >scripting, C, sed/grep), in others it seems to go out of its way to do > >things in such a way as to be as confusing as possible. > > Example? Structures come to mind, though they're not as bad as some things I've come across (can't recall what though). I thought I already gave that, but I guess I didn't. > >2. The people who like to program Perl seem to have a propensity to > >prefer to write code which takes advantage of all the obscure > >features, and generally to write code which is unreadable. > > Well, I guess it depends upon how well you know the language. I can > say the same for just about any language I've ever looked at. > For example, the C code in libc is about as obscure undecipherable as > it gets :) Well, there are certainly people who like to write obscure C as well. It just seems to be part of the Perl culture... I've seen far less readable Perl than C. In fact, I'd say the most readable Perl I've seen was in Learning Perl, and some of that I thought looked kinda gross too. It is as if unreadability was designed into the language. - -- Derek Martin [EMAIL PROTECTED] - - I prefer mail encrypted with PGP/GPG! GnuPG Key ID: 0x81CFE75D Retrieve my public key at http://pgp.mit.edu Learn more about it at http://www.gnupg.org -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE9YlYbdjdlQoHP510RAujqAKCzFvzLIlnNViBmR3bnAuyUO2yAogCgjZv4 TH7aJx4+lIQCj74Bmp88ycU= =twNK -END PGP SIGNATURE- ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Mon, 19 Aug 2002 19:18:32 EDT "Derek D. Martin" said: >1. Perl seems to favor supporting a variety of features with obscure, >meaningless, two-character variables that might be clearer with flags >or arguments to functions that make use of it. Define obscure please. Everything in the perl language is tediously and breathtakingly documented and quickly accessible to any system on which perl has been installed using either the 'man' or 'perldoc' commands. >Whereas in many ways, Perl seems to have gone >out of its way to work like other common Unix tools/languages (shell >scripting, C, sed/grep), in others it seems to go out of its way to do >things in such a way as to be as confusing as possible. Example? >2. The people who like to program Perl seem to have a propensity to >prefer to write code which takes advantage of all the obscure >features, and generally to write code which is unreadable. Well, I guess it depends upon how well you know the language. I can say the same for just about any language I've ever looked at. For example, the C code in libc is about as obscure undecipherable as it gets :) >I reject the notion that it is not possible to write readable code in >Perl. I prefer to think that Perlheads just like it that way. =8^) I think a lot also has to do with coding style. People who write unreadable code will do so in any language. I ardently comment my code far more than the average programmer, IMO. Partially because I can seldom remember what I did in 6 months, and partially because if I were to pass my code around, I want whomever I'm passing it to immediately be able to understand what I was thinking. I think the problem with JAPHs (or "PerlHeads" as you call them) forget that there may be others who don't know the language as well as they do. Additionally, they're also quite expert programmers who also don't believe in commenting their code, believing the code should speak for itself :) -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
First, thanks to Kevin and Erik (and all) for their examples and participation. Second, when I said that one example "doesn't suck" I was just trying to be high-larious, not implying that the other one DID suck. Apologies for any implied slight, and my allergies are my own problem. Third, just as I am a lifelong vi user but secretly believe that emacs users are superior, I am most comfortable with shell scripting but suspect that perl users will always be able to code circles around me. Just don't ask me to maintain their code...! ;-> Thanks again. ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
I think the more interesting question is "How dense is the resulting object code which implements the semantics of the program?". This has been an on-going language design/implementation question for most of the history of computing. For example, a particular program can be implemented in "C" which performs a certain action or actions intended to solve a problem. A high level language like Fortran for example might result in much tighter higher performance object code than the same "C" program. "C" was deliberately designed to inhibit compiler optimizations - the philosophy of the language designers was that the programmer should have more control. Fortran on the other hand performs many optimizations by default and a "C" programmer would need to modify their first iteration of their program to achieve some of the same optimizations. Personally, I prefer readability over terseness. The enemy of reliable, maintainable programs is the terse, clever programmer. Often these terse programs have subtle bugs that are quite difficult to ferret out. Additionally, good compiler designers can out-perform these terse unreadable programs using a myriad of object code optimizations. -Alex P.S. All bets are off however if the programmer implements a better algorithmn... - Original Message - From: <[EMAIL PROTECTED]> To: "Greater NH Linux User Group" <[EMAIL PROTECTED]> Sent: Tuesday, August 20, 2002 9:19 AM Subject: Re: sorting pathnames by basename > On 20 Aug 2002, at 8:07am, Kevin D. Clark wrote: > > It was a one-liner. Take it for what it was. > > I am curious: If that Perl code was optimized for education (as opposed to > source size), what would it look like? I am thinking, specifically, of the > Python example that was posted. Without even knowing anything about Python, > I suspect that code could be made denser, by eliminating temporary variables > and nesting things instead. Can the reverse be done to the Perl code? > > -- > Ben Scott <[EMAIL PROTECTED]> > | The opinions expressed in this message are those of the author and do not | > | necessarily represent the views or policy of any other person, entity or | > | organization. All information is provided without warranty of any kind. | > > ___ > gnhlug-discuss mailing list > [EMAIL PROTECTED] > http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss > ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Mon, 19 Aug 2002 17:17:43 EDT Bill Freeman said: >[EMAIL PROTECTED] writes: > > > >Suggestions for improvement welcome. > > > > Use perl. > > -- > >Use Python Bill, [ Note: this is not intended as the beginning of a flame-fest! ] I'm curious what Python has to offer in this area. I know nothing about the language really, and am quite curious about it. The reason I offered the suggestion of Perl isn't because it's my favorite language, but because the language itself was developed to solve the exact type of text-munging problem mod was encountering. Is Python also a "text-munging" type language aimed at sysadmin type problems? Was it too, specifically designed to pick up where awk and sed fell short? Thanks, -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
[EMAIL PROTECTED] writes: > I am curious: If that Perl code was optimized for education (as opposed to > source size), what would it look like? I dunno, maybe something like this: #!/usr/bin/perl @lines = <>; @sortedLines = sort { ($baseA) = $a =~ m#/([^/]*)$#; ($baseB) = $b =~ m#/([^/]*)$#; $baseA cmp $baseB } @lines; for $line (@sortedLines) { print $line; } __END__ OBTW, while I appreciate Erik's effort (because, in fact, I am learning Python), in actuality, I believe that his program contains a bug: what happens if more than one file has the same basename, for example: /a/a/a/a/a/a/a/a/blah /b/b/b/b/b/b/b/b/blah While Erik's program "doesn't suck", and while it does look nice, I don't believe that it handles this case. None of the solutions that I have posted suffer from this bug, BTW. Regards, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On 20 Aug 2002, at 8:07am, Kevin D. Clark wrote: > It was a one-liner. Take it for what it was. I am curious: If that Perl code was optimized for education (as opposed to source size), what would it look like? I am thinking, specifically, of the Python example that was posted. Without even knowing anything about Python, I suspect that code could be made denser, by eliminating temporary variables and nesting things instead. Can the reverse be done to the Perl code? -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Can any of the Python programmers on this list implement this as a one-liner? Just wondering. (with Python's indentation rules, I think that this would be difficult) Thanks, --kevin PS I could write a very similar program in Perl, obviously. -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
"Derek D. Martin" <[EMAIL PROTECTED]> writes: > At some point hitherto, Kevin D. Clark hath spake thusly: > > Honestly, I wrote that one-liner more with the intent of showing you > > how cool Perl is, not with the intent of scaring you off from Perl. > > And yet the example you provided was far more suited to the latter... In your opinion. In fact, my one-liner is probably the cannonical way that an experienced Perl programmer would have solved that problem (or, at least, pretty close). How is strcpy() implemented in C? Traditionally, the bulk of this function's work is implemented by a loop that can be described as: while (*str1++ = *str2++) ; Every C programmer who is worth their salt will understand immediately what this is doing, and they won't complain that this loop is "too busy" (etc.). They'd probably even write code like this too, when called upon to do so. It is the same thing for the one-liner that I wrote: > I've made some effort to learn Perl, and have written more than a > handful of programs using it, some of which were long, and some of > which were useful (though not necessarily both). The problem I have > always had with Perl is twofold: > > 1. Perl seems to favor supporting a variety of features with obscure, > meaningless, two-character variables that might be clearer with flags > or arguments to functions that make use of it. use English; [snip] > 2. The people who like to program Perl seem to have a propensity to > prefer to write code which takes advantage of all the obscure > features, and generally to write code which is unreadable. It was a one-liner. Take it for what it was. IIRC, I have posted other Perl code to this list that was quite a bit more readable. OBTW, I could have made it a couple of characters shorter. I was typing kind-of fast. > I reject the notion that it is not possible to write readable code in > Perl. I prefer to think that Perlheads just like it that way. =8^) One-liners are not representitive of the readability of Perl code. I hope you agree. Regards, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Erik Price wrote: >#!/usr/bin/python ># ># basenamesort.py ># ># Unix-style filter that sorts a newline-separated ># list of files by the file basename ># ># Example usage: cat files.txt | basenamesort.py > >import sys >import os > >tempDict = {} > >for line in sys.stdin.xreadlines(): > tempDict[os.path.basename(line)] = line.rstrip() > >sorted = tempDict.keys() > >sorted.sort() > >for key in sorted: > print tempDict[key] Wow. That doesn't suck. Thanks! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Tuesday, August 20, 2002, at 12:39 AM, Erik Price wrote: > #!/usr/bin/python > # > # basenamesort.py > # > # Unix-style filter that sorts a newline-separated > # list of files by the file basename > # > # Example usage: cat files.txt | basenamesort.py > > import sys > import os > > tempDict = {} > > for line in sys.stdin.xreadlines(): > tempDict[os.path.basename(line)] = line.rstrip() > > sorted = tempDict.keys() sorted.sort() > for key in sorted: > print tempDict[key] Whoops. It figures that I would forget the part that actually does the sorting. I added it above (the "sorted.sort()" line). Erik -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] > > ___ > gnhlug-discuss mailing list > [EMAIL PROTECTED] > http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss > ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Monday, August 19, 2002, at 05:32 PM, Kevin D. Clark wrote: > > Bill Freeman <[EMAIL PROTECTED]> writes: > >> Use Python > > Please show us the code. #!/usr/bin/python # # basenamesort.py # # Unix-style filter that sorts a newline-separated # list of files by the file basename # # Example usage: cat files.txt | basenamesort.py import sys import os tempDict = {} for line in sys.stdin.xreadlines(): tempDict[os.path.basename(line)] = line.rstrip() sorted = tempDict.keys() for key in sorted: print tempDict[key] # Ugly even for Python, but it does what Michael originally wanted. -- Erik Price email: [EMAIL PROTECTED] jabber: [EMAIL PROTECTED] ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 At some point hitherto, Kevin D. Clark hath spake thusly: > > BTW, this is actually a fairly good example of > > why my immune system always concludes that I'm > > in physical danger when perl code is visible... I would point out that it's just as possible to write virtually unintelligible code in C as it is in Perl. The Twelve Days of Christmas always comes to mind... > Honestly, I wrote that one-liner more with the intent of showing you > how cool Perl is, not with the intent of scaring you off from Perl. And yet the example you provided was far more suited to the latter... I've made some effort to learn Perl, and have written more than a handful of programs using it, some of which were long, and some of which were useful (though not necessarily both). The problem I have always had with Perl is twofold: 1. Perl seems to favor supporting a variety of features with obscure, meaningless, two-character variables that might be clearer with flags or arguments to functions that make use of it. An example is the $| variable... Additionally, it seems to like to take concepts that are common in other languages, and do them in an entirely different way. An example of this would be the equivalent of a structure in C (or Pascal or whatever). Whereas in many ways, Perl seems to have gone out of its way to work like other common Unix tools/languages (shell scripting, C, sed/grep), in others it seems to go out of its way to do things in such a way as to be as confusing as possible. 2. The people who like to program Perl seem to have a propensity to prefer to write code which takes advantage of all the obscure features, and generally to write code which is unreadable. I reject the notion that it is not possible to write readable code in Perl. I prefer to think that Perlheads just like it that way. =8^) - -- Derek Martin [EMAIL PROTECTED] - - I prefer mail encrypted with PGP/GPG! GnuPG Key ID: 0x81CFE75D Retrieve my public key at http://pgp.mit.edu Learn more about it at http://www.gnupg.org -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE9YXzIdjdlQoHP510RApskAJ9ev+dn3CYlwRdo6AdBY5EhRfaCWACgqDGg 1cCbs9Ws6MbZv1UKBJRYSqY= =8Jei -END PGP SIGNATURE- ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
Bill Freeman <[EMAIL PROTECTED]> writes: > Use Python Please show us the code. Thanks, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
[EMAIL PROTECTED] (Michael O'Donnell) writes: > Thank you. I think. For the benefit of those > here assembled, please supply an explanation. OK, since you asked. You have a list of stuff that you want sorted. The problem is is that you want your stuff sorted according to a field contained in the input (the last field). Further complicating matters is the fact that this field is located at a non-constant place in the input field. (I initially thought about using "sort", but then I had trouble with the sort options, and I gave up and used my favorite tool: Perl) Now, just to complicate matters, suppose your input consisted of a million filenames (or so). How to do this efficiently? Big suggestion: finding all of those comparison fields, once per sort comparison, is going to be really expensive... The solution: take the input, generate a list from each line, each element in the list consists of a tuple consisting of the original line plus the comparison key. Sort the tuple-list using the comparison key, and then after the sort is done, strip off all of the comparison keys, returning the original list ({sans} tuples), sorted. This is actually a well-known technique in Perl, called the Schwartzian Transform. Look it up on the web -- there are plenty of good descriptions of it. > BTW, this is actually a fairly good example of > why my immune system always concludes that I'm > in physical danger when perl code is visible... Honestly, I wrote that one-liner more with the intent of showing you how cool Perl is, not with the intent of scaring you off from Perl. Regards, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
[EMAIL PROTECTED] writes: > > In a message dated: Mon, 19 Aug 2002 15:46:40 EDT > Michael O'Donnell said: > > >Suggestions for improvement welcome. > > Use perl. > -- Use Python ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
>[pause to pull-start the 500cc swiss-army chainsaw...] > >perl -e 'print map { $_->[0], "\n" } sort { $a->[1] cmp $b->[1] } map { [$_, @{ >chomp; m#/[^/]*$#}[0]] } ' > >Hope this helps, Thank you. I think. For the benefit of those here assembled, please supply an explanation. BTW, this is actually a fairly good example of why my immune system always concludes that I'm in physical danger when perl code is visible... ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
On Mon, 19 Aug 2002, at 3:46pm, Michael O'Donnell wrote: > My current approach is a bit clunky but works as long as the pathnames in > question contain no spaces, thus: > > sed -e 's;/\([^/]*\)$; \1;' | sort -bfd +1 | sed -e 's; ;/;' Suggestion: Use a star (*) instead of a space. Filenames containing spaces are not uncommon, while filenames containing shell meta-characters are still decidedly rare. -- Ben Scott <[EMAIL PROTECTED]> | The opinions expressed in this message are those of the author and do not | | necessarily represent the views or policy of any other person, entity or | | organization. All information is provided without warranty of any kind. | ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Mon, 19 Aug 2002 16:14:11 EDT Michael O'Donnell said: >So, did you suggest perl just to be a pest, or would >it actually offer an advantage? Let me guess: in perl, >the construct "$@!$*->___++" does exactly what I want... Well, I can't really hope to play "One-upmanship" with Kevin, nor could I ever attempt to come up with something as concise as he did. However, I can offer you this. Perl has a lot of sorting, and file-finding modules built into it. That, combined with hashes, could enable you to write some pretty good file sorting code which is actually readable :) -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
>>Suggestions for improvement welcome. > >Use perl. I might first need to use some of those immuno-suppressive drugs they give to transplant recipients because, although I'd never deny perl's obvious utility, I think I might be allergic to it; every time I look at some perl code I get the heaves and the hives... So, did you suggest perl just to be a pest, or would it actually offer an advantage? Let me guess: in perl, the construct "$@!$*->___++" does exactly what I want... ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
[EMAIL PROTECTED] (Michael O'Donnell) writes: > Given a list of pathnames, I'd like to be able to > sort that list by the basename of each file in the > list [pause to pull-start the 500cc swiss-army chainsaw...] perl -e 'print map { $_->[0], "\n" } sort { $a->[1] cmp $b->[1] } map { [$_, @{ chomp; m#/[^/]*$#}[0]] } ' Hope this helps, --kevin -- Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA) cetaceannetworks.com!kclark (GnuPG ID: B280F24E) alumni.unh.edu!kdc ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: sorting pathnames by basename
In a message dated: Mon, 19 Aug 2002 15:46:40 EDT Michael O'Donnell said: >Suggestions for improvement welcome. Use perl. -- Seeya, Paul -- It may look like I'm just sitting here doing nothing, but I'm really actively waiting for all my problems to go away. If you're not having fun, you're not doing it right! ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
sorting pathnames by basename
Given a list of pathnames, I'd like to be able to sort that list by the basename of each file in the list, ie. the pathname q/r/s/t/u/v/aaa ...would sort ahead of //bbb ...because the basename 'aaa' sorts lexicographically ahead of 'bbb'. My current approach is a bit clunky but works as long as the pathnames in question contain no spaces, thus: sed -e 's;/\([^/]*\)$; \1;' | sort -bfd +1 | sed -e 's; ;/;' ...which replaces the last slash in each pathname with a space, sorts that list of dual-field space-delimited records keyed on the second field, and then replaces the slashes. Suggestions for improvement welcome. ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss