Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
News Books Media Book Reviews

Learning Perl/Tk 65

After a bit of a hiatus, Jason Bennett has returned with a review of Nancy Walsh's Learning Perl/Tk. As the title of the book would indicate, this is an ideal book for those looking to learn the Tk tool kit and Perl. This book assumes a level Perl background, and a little GUI, but is a good intermediate step-click below if you want to know more.
Learning Perl/Tk
author Nancy Walsh
pages
publisher O'Reilly
rating 8/10
reviewer Jason Bennett
ISBN 1-56592-314-6
summary A solid introduction to using the Tk toolkit with Perl. If you have a reasonable Perl background, and a little GUI on the side, you'll pick it up in no time.

Background

Greetings, all. This will be the first in a series of reviews dealing with some Tcl/Tk books I've recently acquired. Since I already have some Perl in my background, I took this one first, both to sharpen my Perl skills, and to find out what this Tk thing is all about. Given that my GUI experience is limited to Smalltalk and Java, Tk is quite easy to use. With Smalltalk, I was too busy wrapping myself around OO theory to enjoy the interface, and Java always seemed to make GUI stuff more difficult than it needed to be (although I still love it). Perl and Tk are strong partners, because they share a philosophy of getting things done without a lot of fuss. Perl and Tk are excellent replacements for any GUI scripting language you might use (read: VB). Read on to see how to jump in!

What's the book about?

This is another book in O'Reilly's Learning series (of which Learning Perl really saved my butt in college), which is dedicated to teaching the fundamentals of a certain topic. I want to compare this series with the Learn XY in 21 days type of books, although I believe that would generally be an insult to the quality of O'Reilly. Once you finish this book, you will have enough of an understanding of Tk to be able to do most small projects. You will know most widgets (although I'll admit my own knowledge is limited here), and will generally be prepared to be productive with Tk in Perl.

What's Good?

In order for you to be able to evaluate the usefulness of this book, it will probably help to understand where I'm coming from. I have a BSCS from Georgia Tech, and have enough languages under my belt to do some damage (Lisp is cool!). In fact, I learned Perl originally for a networking project using Learning Perl. It gave me enough to do what was needed. Having said that, I don't live to program, and in fact I'm not big on reading language books. I don't know every language under the sun, and I don't necessarily learn them with the greatest of ease. In other words, my results should be duplicable by most programmers. The most important thing when reading this book is to know Perl (at least have written some stuff in it), and probably have an idea of what to expect when writing GUI code.

Going into this, my Perl was definitely rusty (having not touched it in a while). I didn't have any trouble diving straight in, however. The Perl constructs used are not overly complicated, and my knowledge was sufficient. (NOTE: make sure you have a very recent version of Perl installed. My Redhat 5.2 needed to be upgraded to m4 before the examples would work. Also, get the errata from O'Reilly.) The early chapters deal with basic constructs and widgets, and spend a great deal of time on the geometry managers (go figure). Each chapter introduces a new widget, although some are used before they are introduced (just nod and smile when you see those and don't worry). There are plenty of examples, code fragments, and exercises to keep anyone busy. I tried to work as many as I could, to get a feel for the language, and generally felt like they were helpful. I never felt completely lost or confused, and generally followed things without much trouble. Having finished the book, I feel confident that, given a little work on my Perl, I could write a useful application with Tk, especially given some research on CPAN for various contributed modules. For me, the book worked.

What's Bad?

Nothing in this book is particularly bad, although there are a few nits I'd like to pick. First, the early emphasis on geometry was somewhat interesting. I'm not sure why I care about grid vs pack when I can barely create a button to put on the screen. For that matter, frames are referenced in a short chapter late in the book, after being used all throughout. If the concept is so basic, why not put it toward the beginning? Also, there were times when the author mentions that an option is esoteric, or generally unused, and then spends much more time than necessary on that point. If it's so esoteric, why is it being covered in a basic book like this one? Finally, there were a few times that the book did not explain a point well enough to me, and I had to divine the answer down the road (like configuring scrollbars). It was not a major issue, but there were some things that could have been clearer.

What's In It For Us?

If you want to learn Tk using Perl, this book will let you do that. It gives a solid introduction to the topic, and on completion, you will be a useful Perl/Tk programmer. Just know your Perl going in, and you will be fine.

Purchase the book over at Computer Literacy.

  1. Preface
  2. Introduction to Perl/Tk
  3. Geometry Management
  4. The Basic Button
  5. Checkbuttons and Radiobuttons
  6. Label and Entry Widgets
  7. Scrollbars
  8. The Listbox Widget
  9. The Text Widget
  10. The Canvas Widget
  11. The Scale Widget
  12. Menus
  13. Frames
  14. Toplevel Widgets
  15. Binding Events
  16. Composite Widgets
  17. Methods for Any Widget
  1. Configuring Widgets with configure and cget
  2. Operating System Differences
  3. Fonts
    Index
This discussion has been archived. No new comments can be posted.

Learning Perl/Tk

Comments Filter:
  • Well this was IMHO one of the better reviews to be posted on /. It was more than just a summary like so many others.

    If only TCL wasn't so strange. (At least to me and I've been using it since 1994!) You wouldn't need to graft Tk onto Perl. On the other hand I find Perl's syntax to be not strange but down right poor.

    Interestingly enough when I was at the Tcl BOF at the 1998 USENIX conf Outserhout seemed surprised that more people were interested in Tk than Tcl.

    Ron Rangel
  • by Anonymous Coward
    . . . but then again, that's the stuff that religious flame wars are made of. I find Perl's syntax pretty natural once you learn what all those weird regular expression codes mean. I've gotten into discussions (no fistfights yet, thankfully) with hardcore C programmers who don't like Perl because it's so unstructured. That is, in fact, the exact thing I like about it. There's enough structure that your code tends not to become spaghettified but not enough to get in the way of coding. For me at least, it lets me think about "How am I going to solve this problem?" rather than "How am I going to force to help me solve this problem?" Programs go together quickly and easily, and tend to be more readable than your average C program. (And having said that, Perl helped me learn C. Go figure.)

    In short, it lets me write code the way I think. If it doesn't let you write code the way you think, well, that's fine. Let a thousand virtual flowers coded in a thousand different languages bloom.

    -- Just Another Anonymous Coward
  • by Anonymous Coward
    Dunno bout you, but I _like_ well-indexed paper books. Reading computer displays can be much more taxing than reading book print. Also, books tend to be hardier and have longer battery life than laptops..

    Besides, I learn best when I have a book (usually ORA), a few browsers, a few rxvts viewing manpages, and a few vi windows. Makes for very rapid education..
  • Does Tk have a grid widget like in VB ?

    Thanks, Aaron Newsome
  • Posted by FascDot Killed My Previous Use:

    ...at least the last time I tried to use them about 3 months ago.

    A lot of the basic properties are there, but there's very little in the way of tutorials on higher level stuff.
  • Posted by FascDot Killed My Previous Use:

    The only FTP site I could find had a version number of 0.1.17--that can't be right. Where's the latest?
  • Check out TkApache - a PerlTk front-end to Apache [eunuchs.org] for an example of what it can do! :)

    I have this book, and it's nice to have a solid book, it's not THAT much more than what's out there already.

  • ... which is fine for hacking trivial cgis in your bedroom, but almost useless for long-term ongoing team projects. languages like pl/sql and ada force you into nice structures and enforce data types.
  • i *very* much doubt perl/tk is faster than VB5, and it doesn't even come close to VB's database app RAD capability.
  • I couldn't disagree more with your evaluation of Learning Perl. It had me writing working (albeit goofy) perl scripts before I even got out of the first chapter.

    All in all, I would say that it was the best programming language book that I have ever read.

    Of course, it goes without saying that everyone is different. That's why I would recommend going to a bookstore and checking things out for yourself.
  • Does anyone know of any programs to convert Visual Basic programs to Perl/Tk programs automatically, or at least semi-automatically? Something like that would be very handy to remove one of the major arguments small shops have against moving away from MS OSs. If their in-house VB programs can be automatically moved to Perl/Tk and run faster to boot, moving to Linux or FreeBSD would be a much easier sell.

    Doug Loss
  • I don't disagree with anything you've said. What I'm talking about is something to take existing VB programs generated by people who used VB to get some need-specific job done (and who probably couldn't have programmed in any other language anyway) and convert it to Perl/Tk (or Python, or anything other than VB). Would it generate ugly code? Almost undoubtedly. However, it would have moved all their proprietary stuff to a non-Windows OS. It could then be cleaned up as needed. The upshot is that if they have to rewrite their VB apps in a better language, they won't do it and they won't move to Linux. As I said earlier, that's the point of the convertor, to get them to move.

    Doug Loss
  • I know about this. It's a Java applet, IIRC, so it requires java to be installed on the machine. Also, being binary only it will run VB code, but it doesn't convert it to something native to the system it's running on. That would mean that any maintenance or modification to the VB app itself would still have to be done in VB, and the use of VB is what I'm trying to get away from.

    Doug Loss
  • Well, it's definitely faster that VB5 on a Linux system. And without getting into a religious war about whether VB is better/worse than whatever other language we're talking about, my point isn't just to get better performance out of the VB apps (although I consider your opinion about VB5's performance unlikely) but to get rid of VB entirely as it just isn't a viable non-MS OS possibility.

    Doug Loss
  • Geometry management is an extremely powerful and useful concept. I don't know Perl/Tk, but I do know Tcl/Tk, and I can tell you that without geometry management, Tk would be just another "me too!" GUI toolkit. Geometry management lets you construct user interfaces quickly without worrying about the details of where exactly all the widgets get placed on the screen.
  • It's garbage. A coworker of mine seems to agree - after both of us trying to find out even the most basic information about Perl the other day, we both independently wound up at bookstores that evening looking for something better. I came up with:

    Perl by Example by Ellie Quigley
    and
    Perl Power! (can't remember author)

    Both are quite nice - and you'll _really_ want Perl by Example - Perl is so obtuse at times that you'll need the line by line examples to figure somethings out. How 'Learning Perl' ever came to be respected, I'll never know - unless it's because the authors are influential, which is a ridiculous way to evaluate a book, IMO.

    Anyway - my 2 cents' worth. Good luck!
  • I very much agree with the suggestion to go to
    the store and check them out in person. Everyone
    learns a little bit differently than the person
    next to them, and that's the only way to be
    sure...other than nuking the site from orbit,
    of course! :)
  • I was just thinking about posting this to a newsgroup but this seems like a reasonably on-target forum; yesterday I tried out the Tk/Perl tax package [freshmeat.net] recently posted on Freshmeat. It failed, saying Tk.pm wasn't installed. I do have both Tk and Perl packages installed but no file by that name. I searched the perl archives and didn't find a Tk.pm file, and there was nothing by that name in the Tk module directory. I'm sure the problem is my lack of familiarity with the Perl module system but I'd appreciate any advice. (This is going to run on MkLinux so pointers to source would be helpful.) Thanks....

  • In the time it takes to write a VB program, I can churn out 3 or 4 Perl programs of equal complexity, because I don't have to fiddle around with the GUI to do it. And my Perl programs will, in general, be more flexible, more robust, and 100% more cross-platform-able.

    And since perl/TK works just fine on windows, you're not getting hurt at all, it's just all value-added. Oh, and you don't have to pay $1K+ (US) for the compiler.

    Any program that translated VB to Perl would, by necessity, generate ugly code because VB code is just generally ugly. Better to do the job right the first time, I say. Or, you can always just wait for Micro$oft to come up with VB for Unix. >:)

  • There is a Grid widget, but it's a little flaky.

    Check out the FAQ (I can't remember the URL, but
    it's worth poking around the CPAN directory on
    CPAN, it's in a module listing included there).

    The Tk module's worth the masses of disk space it
    uses up just for the TkPod addon.

    Chris Wareham
  • I've found the tutorial to be almost as good
    as a reference. For the more detailed points I
    currently turn to the mailing lists, which have
    some very knowledgable posters.

    Yeah, the rest of the GTK+ docs are a little
    sparse at the moment. For low level stuff, volume
    one of the O'Reilly X Programming series is good,
    the one on Xlib. The GDK in particular maps quite
    closely onto the functionality of Xlib - but with
    a much, much nicer API.


    Chris Wareham
  • (see subject line)
    Chris Wareham
  • Perl and Tcl may be lame if you're after speed and compactness, but for rapid solutions to everyday
    problems they're fantastic. After all, that's
    what VB is used for in the Windows world - quick
    apps that may be a little kludgy and slow, but
    that get the job done without taking an age to
    program.

    They're tools for a certain job (or jobs), don't
    knock them.


    Chris Wareham
  • Tcl has always struck me as a little less anarchic
    than Perl. The KDE to Perl's Gnome if you're
    into weird analogies.

    With version 8, Tcl/Tk really came of age, and I
    have actually found myself questioning my
    otherwise firm devotion to Perl. Especially when
    I encountered oodles of memory leaks in the Perl
    Tk module.


    Chris Wareham
  • Tell you what: when I have an extra cordless PDA that I can toss around, spill coffee on, use to annotate various pages of documentation, place any convenient thin object (including, temporarily, my fingers) in to mark my place, has sufficient resolution so lots of text is readable from a few feet away without strain, and can afford to misplace and buy another copy once in a while, lemme know.

    obsolete, my arse...
  • There is already a VBVM (VisualBasic Virtual Machine) for linux, but its in binary only. I personally lost the URL for it, but it wasn't hard to find.
  • > 99% of the worlds useful information is still in printed media. Printed media still have great advantages over online media: > lighter, smaller, and more portable; when was the last time you dragged your computer into the bathroom? - Im building a wearable computer > don't need electricity - Whats it matter when I already have my computer on? >much higher resolution; - 640x480 is fine. >use passive lighting; - thats what the brightness knob is for >easier on the eyes - brightness knob again. >more permanent urls tend to change a lot - save a local copy >I love the smell of new books ;} - get one of those air freshners for cars that smells like a new book, or just use the computer in Barnes&Noble :)
  • I have used Perl/Gtk and it is VERY easy, documents would be nice.. but the same information could easily be reached by reading the source to slash.pl, iceconf, or any other perl/gtk app.. Maybe I should write a book on perk/gtk, maybe after I finish this term paper.
  • Actually, the one I have is an elf binary, but the author of it must be a loyal windows user because he added an .exe extension to the binary file ;p
  • The obvious one: "Learning Perl" by Randal Schwartz and Tom Christiansen. Published by O'Reilly.

    http://www.oreilly.com/catalog/lperl2/

  • I'm not familiar with "Perl by Example", but when
    I want working examples of Perl code, I go to
    "The Perl Cookbook" by Tom Christiansen & Nathan Torkington, also on O'Reilly.

    (And "Learning Perl" may not be a perfect book -- myself I was a bit put off by the artificial nature of the examples in the first chapter -- but it's hardly "garbage". )

  • I thought "Learning Perl" was great. At that time (a year ago) I had never used a *nix system, ever. I had tried Perl but was confused by it's Unix slant. Learning Perl On Win32 systems helped me out alot.

    It was Perl, more than anything else, that got me into Unix, and hence, Linux.

    I got more out of chapter one than I do out of most computer books...

    'course I already had a good base in c/c++...
  • I just installed Perl/Tk yesterday. Got the book (Learning Perl/Tk) earlier today. Wrote a program already. (really just added a GUI to an existing program).

    It's a good book, and very informative. I spent all last night fooling with Perl/Tk, and searching the web for good online introductory material. It was slim pickins, let me tell ya.

    I got more done after spending 20 minutes reading the book than I did with 4 hours of searching and trial and error.

    Combine Perl/Tk with perl2exe, and who needs VB? Now my exact same Perl/Tk program can run on Linux or Win32, and if they don't have Perl installed, I just perl2exe it!

    VB who?
  • What's a good book for someone who wants to start from square one on Perl?



  • Perl is as structured as you make it. It's up to the programmer. That's the way Larry wants it.
  • ...yesterday I tried out the Tk/Perl tax package recently posted on Freshmeat. It failed, saying Tk.pm wasn't installed. I do have both Tk and Perl packages installed but no file by that name. I searched the perl archives and didn't find a Tk.pm file, and there was nothing by that name in the Tk module directory. I'm sure the problem is my lack of familiarity with the Perl module system but I'd appreciate any advice.

    I'll make a wild guess that you're getting burned by some historical confusion concerning Tcl/Tk interfaces used by Perl. Unfortunately, there's a Tcl/Tk package (not likely to be what you want), an ancient Tk package (ditto, surprisingly enough) and what you do want: either Tk400.202.tar.gz, or, possibly, Tk800.012.tar.gz (which is based on the version of Tk used in Tcl/Tk 8).

    Of course, it's possible that you do have the right version of perl/Tk, but don't have them installed correctly; re-installation might do the trick there.

    Or, it's possible that the perl/Tk tax package isn't giving you useful feedback about what it really wants.

    King Babar

  • I assume you mean a grid geometry manager, not a widget. Tk has a grid geometry manager. There is also another grid geometry manager available called "table" which is part of the BLT package (www.tcltk.com/blt) that is a bit easier to use IMHO. BLT also has a very complete 2D graph widget which is one of the main reasons I picked Tk for a graphing application I am writing.
  • Personally, I find Tcl syntax to be a bit more natural than Perl, but they're both useful languages and each has it's strong points. Keep in mind that Tcl was originally designed to be an embedded scripting language for applications. There are some shortcomings, such as way too limited data types and structures, but I have written some medium sized applications (~5000+ lines of code) in Tcl/Tk in much less time than it would have taken using c and a GUI library. BTW, Tk can be used in c, it's just more work.
  • Anybody who likes Tk should check out the incr Tk / Iwidgets packages. One place to get them is www.tcltk.com. They make life much, much easier when creating any size GUIs.


  • GUILE-Gtk Rocks!!!!!
  • I read PERL BY EXAMPLE, by (I think) Sam Medinets. You can find it online at the Macmillan Personal Bookshelf, at http://www.mcp.com/personal [mcp.com].

    Take a look at it, it's a great book.
  • Just read the book in question and loved it.

    Having spent the last year with MS development tools such as MFC before learning the PerlTk module available from ActiveState I was enthralled with Perl's syntactic and stylistic flexibility, plus, the blazing speed I can design/build complex event driven GUIs without depending on brittle proprietary Wizard built hocus-pocus code.

    I'm not surprised most users/consumers don't seem to respond well to menu driven console programs. PerlTk is a wonderful way to enhance your sysadmin scripts as well, and escape from those convoluted menus and argument lists. All this while you write code that can run across multiple platforms with little or no tweaking. What's not to like?

    Nancy Walsh's book _Learning_Perl/Tk_ is supporting evidence for my theory that Perl programmers write better books.

  • As all files are potential bases for data, and the sheer volume of ASCII text files vastly overwhelms any amount of data accessed via the database apps VB5 optimally targets, I posit, Perl Master-of-Strings that it is, with a Perl/Tk GUI exudes a more complete and universal RADness than VB5. Want to race IDE's now? puurrrrrrr...
  • Hope you haven't purchased _Perl_Buy_Example. It can be downloaded for free from http://www.rcs.ru:8102/useful/Perl5/noframes.htm

    If you are into all-inclusive tomes then be sure to scope out _Perl5_Complete_ published by McGraw-Hill ( their the ones that like to put corporate ads into the textbooks of elementary school children and then blame it on the companies that purchased the space ... but, what the heck, no-corporate-body is perfect ). Once you really dig into Perl you may well change you mind about O'Reilly's Perl books.

For God's sake, stop researching for a while and begin to think!

Working...