Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Pronounceable syntax or beloved punctuation?

by Juerd (Abbot)
on May 17, 2002 at 00:18 UTC ( #167151=perlmeditation: print w/ replies, xml ) Need Help??

Hi,

I found myself using glob and readline (the words) more and more. Not only to avoid some annoying problems with the shared angle bracket syntax, but also because I think it's clearer. I also tend to use qx() instead of backticks, and and or instead of && and || (not only for precendence reasons), etcetera.

How do you feel about this? Do you think <*.txt> is better than glob '*.txt'? Is <$handle> prefered over readline $handle? And what about backticks: do you think ' and ` look different enough to use backticks?

I'd like to know how other monks think about this TIMTOWTDI/style thing :)

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Comment on Pronounceable syntax or beloved punctuation?
Re: Pronounceable syntax or beloved punctuation?
by tadman (Prior) on May 17, 2002 at 00:56 UTC
    I think glob and readline are great at specifying exactly what you are doing, and both are resistant to casual errors, especially when your glob and filehandle can look so close:
    my $line = <$fh>; # Filehandle? my $file = <*fs>; # Glob?
    Much better to be specific, like you say:
    my $line = $fh->readline(); # Filehandle! my ($file) = glob("*fs"); # Glob!
    The angle brackets and the whole DWIM thing are for "programmer efficiency" and not necessarily "program clarity". In some cases, you would want to avoid them entirely.
Re: Pronounceable syntax or beloved punctuation?
by Mr. Muskrat (Abbot) on May 17, 2002 at 03:46 UTC
    I prefer glob '*.txt' to <*.txt>. Why? I think it's easier to understand what is going on.
    And the use of readline, well, it really depends on the situation. Sometimes, it just makes more sense to use <$fh>.
    My 2¢.

    Who says that programmers can't work in the Marketing Department?
    Or is that who says that Marketing people can't program?
Re: Pronounceable syntax or beloved punctuation?
by Sifmole (Chaplain) on May 17, 2002 at 11:34 UTC
    I guess I have been reading code too long because when I read &&, ||, !, etc they read right off -- but sometimes I have to catch myself when I seed "and" and/or "or".

    As for the globbing and readline. I use glob/readline when I am not looping and use the angle brackets when I am. Makes sense to me that way.

(jeffa) Re: Pronounceable syntax or beloved punctuation?
by jeffa (Chancellor) on May 17, 2002 at 15:07 UTC
    1. <*.txt> vs. glob '*.txt':
      Depends. A neat trick i lifted from merlyn is to use File::Find to find your target files and push them to @ARGV via:
      push @ARGV, $File::Find::name if /MAGIC_CONDITION/;
      then you can modify their contents via the empty angle brackets: <>. I don't think you can do that with glob ...
    2. readline over angle brackets:
      I tend to use angle brackets - guilty of lazy typing. ;)
    3. backticks
      I try to avoid them anytime i can. When i first started using Perl i used them a lot. Too much. Then i found system and exec, and IO::Pipe among other CPAN modules that can replace backticks.
    All in all, i think a good exercise is to force yourself to practice The Other Way. Not necessarily in your production code, but in the throw-away scripts that you write from time to time. Balance is good. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      you can modify their contents via the empty angle brackets: <>. I don't think you can do that with glob ...

      Well, this is the one case where I prefer angle brackets (in this special case often refered to as "the diamond operator") over the readline function.

      You were right about this not being able with glob, as empty angle bracket expressions are handled by readline :) <> eq <ARGV> eq readline *ARGV (but only if the three lines (records) are stringologically equal).

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

        Actually, you don't need * in readline *ARGV, readline ARGV is enough.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://167151]
Approved by stephen
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-10-21 20:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (110 votes), past polls