Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Newline's creep in, while using Tie::File

by Bod (Scribe)
on Nov 17, 2020 at 00:31 UTC ( #11123724=note: print w/replies, xml ) Need Help??


in reply to Re: Newline's creep in, while using Tie::File
in thread Newline's creep in, while using Tie::File

First off, always use strictures

If they should always be used...why are they not on by default?

  • Comment on Re^2: Newline's creep in, while using Tie::File

Replies are listed 'Best First'.
Re^3: Newline's creep in, while using Tie::File
by GrandFather (Sage) on Nov 17, 2020 at 01:08 UTC
    If they should always be used...why are they not on by default?

    For backwards compatibility. Making strictures on by default for newer versions of Perl would break most old or poorly written Perl code. If you use 5.012; strictures are on by default.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

      I'm probably asking the wrong person...but...is it a universal belief that strictures should be on or a majority belief? Is there an argument for leaving them off?

      I have never used them although I would not argue that my code could be held up as best practice or even good practice - other than it does everything it was designed to do and performs non-trivial tasks. On that basis, it works as well as can be expected. I am aware of some of the problems they eliminate and code so these issues do not arise.

        The times when it's sometimes useful to not have strictures:

        • Perl one-liners. That is perl -e'...'. If your code is literally one line, then the rigour that strictures enforce is unlikely to benefit you much and will just force you to type more.
        • When you want to use symbolic references. But in these cases, you can just do no strict 'refs'; in a small scope, like a do {...} block.

        Other than that, use strict everywhere. use warnings is often useful too, but use strict is vital.

        Judging by replies here it is a majority belief that strictures should always be used.

        For things like variable name typos or scoping issues use strict; can save bulk time and very red faces. The cost of including strictures (two lines of boiler plate code) is trivial compared to the time and cost they can save. Can you honestly say you've never fat fingered a variable name or misremembered what you called a variable?

        Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re^3: Newline's creep in, while using Tie::File
by perlfan (Vicar) on Nov 18, 2020 at 19:57 UTC
    Perl 7 (not sure of the equivalent 5.x version but I think it is 5.32.0) is starting off with strict and warnings 'on' by default. They are not on by default in 5.x because it would break a lot of existing code.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-11-26 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?