Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

RE (tilly) 2: Regarding style

by tilly (Archbishop)
on Oct 25, 2000 at 03:20 UTC ( [id://38251] : note . print w/replies, xml ) Need Help??

in reply to RE: Regarding style
in thread Regarding style

I have to disagree on a couple of those.

First of all the diamond operator does not just save 5 keystrokes. Instead it allows you to build filter programs that have a standard (and well-defined) behaviour without your having to build logic to open, test the open, read, close, test the close, get the next filename, etc. When you need it, it is very nice to have. Of course people who use it to avoid writing STDIN are being silly.

But I use the diamond, and not for obfuscation.

As for m operator, I use it as well. Why? Well if I want to match a pattern with forward slashes in it, it is often very nice to use m and a different delimiter. So I don't use it often, but unless I am nobody...

Replies are listed 'Best First'.
RE: RE (tilly) 2: Regarding style
by merlyn (Sage) on Oct 25, 2000 at 03:34 UTC
    Continuing on the diamond theme, I usually flag "dangerous" anything during code reviews that look like:
    print "Some prompt? "; $input = <>;
    Why? Because that program works fine when you run it without command-line arguments. But what happens when some other part of the program needs a command arg for a toggle or something? Oops!

    And saying "well, sometimes I want to get stuff from files instead of STDIN" doesn't fly, because then you get the extra prompts!

    For me, the only proper combination is:

    • print "..."; $input = <STDIN>;, or
    • $input = <>;

    In other words, if you're interacting, use the explicit filehandle. Otherwise, suck from diamond.

    -- Randal L. Schwartz, Perl hacker

RE: RE (tilly) 2: Regarding style
by AgentM (Curate) on Oct 25, 2000 at 03:35 UTC
    Don't consider what i say a personal attack- in the end it is a stylistic matter. If you ant to build a filter system using the diamond operator, go right ahead- but again, it's simply a matter of taste, not code quality or obfuscation. Honestly, the only reason I mentioned m is because I haven't seen it in code for quite a while and you will never encounter a situation where it is required.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.