Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Why Perl Docs examples do not use strict and warnings often (updated)

by haukex (Bishop)
on Nov 20, 2021 at 12:31 UTC ( #11138974=note: print w/replies, xml ) Need Help??


in reply to Why Perl Docs examples do not use strict and warnings often

I was browsing through the Perl Data Structures documentation and noticed that though the document suggests using strict, it's not used in any examples.

Actually, it says "WHY YOU SHOULD ALWAYS use strict".

And what alternative do you suggest? Putting it in every example would make the examples longer and the document harder to read, which is why there's a whole separate section near the start of the document explaining it. Many of the examples also run fine in the absence of strict and warnings. <update> To clarify, obviously one should still always use strict and warnings. But the documentation does still cater to those who don't. Plus, not every code snippet is intended to be a full program. If a code example were to fail in the presence of use strict; use warnings;, I'd call that a documentation issue. But again, I still don't see any concrete suggestions in this thread. </update>

perlintro, the Camel, Modern Perl, and many other resources on learning Perl explain fairly early on why one should always Use strict and warnings. use v5.12; and up, which is required for many modern features to work, also turns on strict.

How's someone who's new to Perl supposed to know when some internally provided variable is being used vs when a user created variable is being used in the code?

From context and from trying out the examples.

So just in case this isn't a troll: Feel free to submit patches for cases that you think are unclear.

Replies are listed 'Best First'.
Re^2: Why Perl Docs examples do not use strict and warnings often
by Anonymous Monk on Nov 20, 2021 at 13:46 UTC
    I love Perl and have zero interest in trolling my beloved language.
      I love Perl and have zero interest in trolling my beloved language.

      Anonymous posts with complaints and no suggestions to improve things tend to give that impression, unfortunately.

        Please try to take it easier. :)

        We had many trolls recently, but IMHO this question regarding perldsc is legit.

        For example:

        Count how many times my is missing here

        Declaration of an ARRAY OF ARRAYS @AoA = ( [ "fred", "barney" ], [ "george", "jane", "elroy" ], [ "homer", "marge", "bart" ], ); Generation of an ARRAY OF ARRAYS # reading from file while ( <> ) { push @AoA, [ split ]; } # calling a function for $i ( 1 .. 10 ) { $AoA[$i] = [ somefunc($i) ]; } # using temp vars for $i ( 1 .. 10 ) { @tmp = somefunc($i); $AoA[$i] = [ @tmp ]; } # add to an existing row push $AoA[0]->@*, "wilma", "betty"; Access and Printing of an ARRAY OF ARRAYS # one element $AoA[0][0] = "Fred"; # another element $AoA[1][1] =~ s/(\w)/\u$1/; # print the whole thing with refs for $aref ( @AoA ) { print "\t [ @$aref ],\n"; } # print the whole thing with indices for $i ( 0 .. $#AoA ) { print "\t [ $AoA[$i]->@* ],\n"; } # print the whole thing one at a time for $i ( 0 .. $#AoA ) { for $j ( 0 .. $AoA[$i]->$#* ) { print "elem at ($i, $j) is $AoA[$i][$j]\n"; } }

        > > > Many of the examples also run fine in the absence of strict and warnings.

        And they still would with my declarations for all Perl 5 versions, even without 'use strict'.

        update

        But they would fail for versions not supporting ->@* and ->#* , which makes the backwards compatibility argument even more dubious.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2022-01-19 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (55 votes). Check out past polls.

    Notices?