Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Sometimes I get the feeling that simply the look and feel of the code is the reason to do so.

Or maybe just the effort to write the code in the first place. Or missing awareness.

There are many more similar but less obvious cases. For example code that interpolates an array into a double-quoted string depends on the value of $". Code that uses print implicitly uses $\ and $,, and if you use readline (or <$fh>) or chomp you'd better hope nobody messed up your $.

And good thing that $[ is deprecated.

And your seemingly harmless loop while (<>) { } gets an entirely new meaning if $^I is set.

Speaking of <>, did you know that it executes code for you?

$ perl -we 'while (<>) { print }' 'fortune |' To downgrade the human mind is bad theology. -- C. K. Chesterton

So you see there is a whole scale of things you should consider when you want to write truely robust and correct code. But once you start to write your code as

sub do_something { my ($filename, @rest) = @_; return unless defined $filename; # ensure basic sanity: local $/ = "\n"; local $, = ''; local $\ = ''; local $" = ' '; local $@; # we might want to use eval { } }

you get a lot of boilerplate code, and writing Perl stops to be fun.

So you can either leave Perl 5 for good, or decide where on your scale between fun and correctness your code should be. Don't condemn anybody for using a simple truth check instead of defined, but not for failing to reset all used global variables in each routine that could be called from the outside.

Note that Perl 6 drastically reduces the number of global and special variables, and most built-in functions don't depend on them to the same degree as in Perl 5.

In reply to Re: Wrong idioms by moritz
in thread Wrong idioms by McA

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (4)
    As of 2018-05-20 11:42 GMT
    Find Nodes?
      Voting Booth?