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

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.
  • splitext is cleaner? (Score:3, Informative)

    by da (1525) on 2003.09.03 12:22 (#23797) Homepage Journal
    From the python docs [python.org], it appears that os.path.splitext will always assume the extension contains at most one period, which according to p. 328 of Perl Cookbook (1st ed. :-) is just why File::Basename requires a regular expression: Consider ".tar.gz"- is the extension ".tar", ".gz.", or ".tar.gz"? By specifying the pattern, you control which of these you get.

    So yes, the default for python looks cleaner; but it's less flexible. In the best of all worlds: perhaps File::Basename::fileparse should default to the pattern "\..*" to be more DWIMy.

    Come to think of it, is File::Basename that fugly as-is? Wouldn't something like:

    ($junk, $component, $flavour) = fileparse($file, "\..*"); look clearer than:

    ($component, $flavour) = $file =~ m{^.*/(.*)(\..*)$}; # extract suffix

    (speaking as somebody who knows no python; and hasn't used fileparse much. Maybe you had a reason to avoid fileparse I didn't see!)

    --

    -DA [coder.com]

  • uhmmm... (Score:2, Insightful)

    Was that script supposed to work? It chokes hard on a perl -c. Mostly from not declaring variables. It also has a syntax error on this line

    $page = sprintf("\n";

    (missing left bracket)

    And interesting look at perl and python none the less.

  • Well, I found it easier to read. :-)

    My complaint about the python code is that __main__ stuff. It's just not needed at all in that script. It's only needed in the case you have a module and you want it to do something if it's executed as well.

    But then again, I love the idea of the language actually forcing you to be consistent with yourself when you're indenting. Most of the complaints I see about python state that it forces you to indent according to a certain set of rules. This is crap. All you h

  • I took a brief gander at the Perl [torkington.com] and Python [blosxom.com] versions in that order.

    My first impression, after reading each in the browser for about a second each:

    • The Perl version starts with a nice long comment that describes WTF this script does.
    • The Python version starts out with gobs of plaintext
    • Oh, wait, it's not python code
    • Oh, wait, it starts out with """
    • Oh, wait, that's a triple-quoted strong. Where does it end?
    • Oh, wait, the python program starts out with pretty much the same commentary as the Perl program
    • I found the Python """ idiom to be no harder to get used to than HEREDOCs.
      • ...but we don't use HEREDOCs for block comments.
        • You've never seen anyone use a HEREDOC for a block comment? You've lived a sheltered life.

          That particular block comment is special. Python associates it with the class object as a special documentation string (__doc__, iirc).

    • The beauty of the triple quoted string is that the documentation is then part of the code. It's available as __doc__ and available to be referenced from your code. Now you can do nice things with it like provide online help automatically from classes / methods.

      -Dom

      • The Perl version starts with a nice long comment that describes WTF this script does.
      • The Python version starts out with gobs of plaintext.

      Then the files aren't really equivalent. Python's """ foo """ multiline comment construct is more equivalent to Perl's POD, not to heredocs.

      Now if you want to complain about the readability of POD, that's one thing, but it's not fair to criticise the Python script for using the language's documentation mechanism when the equivalent comment in the Perl script would

      --


      --
      DO NOT LEAVE IT IS NOT REAL.

      • it's not fair to criticise the Python script for using the language's documentation mechanism when the equivalent comment in the Perl script would have been using POD to accomblish the same thing.

        I'm not criticizing the script, I'm criticizing the language.

        This isn't about docstrings vs. comments, or Pod vs. triple-quoted strings. It's about making different things look different. The combination of triple-quoted strings and their use as docstrings hurts readability because you have to parse them t

  • use Fatal qw( open close );
    --
      ---ict / Spoon