develooper Front page | perl.perl5.porters | Postings from January 2014

perldwim document

Thread Next
Brad Gilbert
January 30, 2014 22:37
perldwim document
Message ID:
In response to
which ask where in the documentation to find out about while(readdir $dh){...}
becoming while(defined($_ = readdir $dh)){...}

I went and created a document that lists several modifications that
Perl does for you.

This includes the optimizations for:

    for( 1..10 ){...}
    if( 0 ){...}
    my($a,$b,$c); # padrange

and the DWIM-ness of:

    while( <> ){...}

My plan for this document is to be a one stop shop for most of the code changes
that happen during compilation.

The reason I combined optimizations with DWIM code changes, is that the reasons
you would want to know about them are for the most part the same.

For example if you knew that these two for loops were mostly
equivalent, it could
change your mind as to which to use:
    for my $i (0..$#a){...}
    for( my $i = 0; $i<@a; $i++ ){...}

If you knew that lexicals that were defined next to each other was faster you
wouldn't write this:

    my $a = 0;
    my $b = 1;

Instead you would write this:

    my($a,$b) = (0,1);

So does this make sense to add to the official documentation?
Attached as both a file and a patch.

I also attached a change to perl5120delta as perldwim references it

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About