Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

avik (3911)

avik
  (email not shown publicly)
Yahoo! ID: topchyan (Add User, Send Message)

Journal of avik (3911)

Wednesday May 07, 2003
02:23 PM

Tough Camel

[ #12062 ]

Programming in Perl is difficult, because it is not intuitive. It is good, though. Sometimes I experience a certain relief when I find an elegant solution to an old dilema. And more often than before I put comments like # THANK YOU, LORD! or # Glory to God in the Highest! inside my code. Why? Because I'm not a perl programmer, I am a perl user, I suppose. Although I managed to write quite an extensive application in Perl, I feel like my learning of this language will never end. Unfortunately.

Don't you wish you would be able to say "I speak Perl fluently". How many of you out there can say that honestly? Does Perl have to be difficult?

How about one of my recent eurica's:

sub copy_button {
    my ($item, $item_id, $parent_id) = @_;
    my $kids = {
        pilot => 'survey',
        survey => 'section',
        section => 'question',
        question => 'option'
    };

    my $ref = $dbh->selectall_arrayref("
        SELECT ID, NAME FROM $$kids{$item}s
        WHERE $item\_id = $item_id
    ");

    return submit({
        name => 'copy_'.$item.'_'.$parent_id,
        value => 'Copy'
    })
    . popup_menu({
        name => 'source',
        value => [ map ($$_[0], @$ref ) ],
        label => { map {$$_[0], $$_[1]} @$ref }  # Glory to God in the Highest!
    });
}

I wish it would be simpler. Should I try Ruby?..

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Perl is like natural languages, it becomes more and more intuitive once you assimilate the idioms.

    Your code would be easier to read if you write
        { map {$$_[0] => $$_[1]} @$ref }
    to underline the fact it builds a hash. It's a common idiom.

    (On the other hand, you can write
        { map @$_, @$ref }
    as well. I wouldn't recommend it.)

    My learning of perl has not ended yet either. I don't think it's discouraging.
    • Like natural languages, you can talk baby talk in Perl and communicate usefully. And, like with natural languages, there are always new levels of mastery possible. Most of us are not yet capable of writing the equivalent of Romeo and Juliet in Perl.
  • If you want to jump in the deep end, or just need to make this half as long and a little more complex, or want to learn some Perl idioms as quickly and painfully as possible (figuratively speaking), go to the Monastery [perlmonks.org] and post in Seekers, indicating that you're looking to make this shorter and sweeter. Ask nicely. (Read the Friendly FAQ on posting first, it'll save you a lot of time and trouble later.) You'll get a lot of responses, most of which will include rewrites of your code in maybe one-third as
    --

    ------------------------------
    You are what you think.
    • I still think that simpler is better. Specially, if it requires to be passed around to another (unsuspecting) individual, other than yourself. So called "Monastery" is a good idea, can't argue with that, but, excuse me, Perl is not a religion, it does not require a monastery, monks or following... It's a programming language... Right?...
      • Yes and no. Some people like it so much that they become, more or less, "disciples of the faith".

        I think it's more about what it is to you. If you want it to be a regular ol' programming language, it's certainly that. But there is a sense of community that follows the language around the battered* landscape of the Net, and the resource that the community can be is invaluable compared to the language.

        I know it's frustrating at times. Just yesterday night I banged my head against regex after regex, an

        --

        ------------------------------
        You are what you think.
      • Perl is a society, and we use a lot of analogies for that society.

        If it makes you feel better, pretend the monks are Jedi adepts. Stronger in the force I feel you growing, young padawan! :)

        --
        J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • by VSarkiss (704) on 2003.05.08 13:53 (#19934) Journal

    So you're saying you're a novice. That's OK. As Larry said, "You can write baby Perl and we won't laugh." But you may want to learn the seven stages of a Perl programmer [frii.com] and see how soon you will become a Perl Adept. (I'm still working on it myself.)

  • ...or any other language. Languages capable of expressing the whole of human existence are large, complex things. Languages capable of expressing this *elegantly* are even more so. Fortunately, we don't need to know the whole language to be fluent in it. Even though I don't know what "pseudoconcha" means, I can get along without that piece of information. More importantly, I know how to find out what it means.

    As if that wasn't enough, Perl is constantly growing. The community, the coding standards, t
    • This is deep. Thanks for your comment back in July. I'm getting better in learning Perl idioms and ways to do job better. Still use VBA for quick analytical projects, though, it's just so much easier to put something "quick and dirty" together than it would be in Perl. But Perl really saves a lot of my time on some things where VBA just gives up.