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

perldwim document

Thread Next
From:
Brad Gilbert
Date:
January 30, 2014 22:37
Subject:
perldwim document
Message ID:
CAD2L-T347jBDzCptwvGPnXqyRwax7bOiAm2gOqa3tUXNB8Lg_A@mail.gmail.com
In response to
http://stackoverflow.com/q/843430/1337
and
http://stackoverflow.com/q/844625/1337
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
etc.

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About