Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Perl 80 Chars perl line Rule

by anshumangoyal (Scribe)
on Oct 16, 2012 at 08:18 UTC ( #999255=perlquestion: print w/replies, xml ) Need Help??
anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I have around 100 Perl file which I want to follow 80 chars per line rule. I tried using perltidy for the same. It works fine except that the print and die statements are indented wrongly. For a print:
print "-file Run Test Cases from this 'xlsm' File. Default += 'SanityTestCases.xlsx'.\n";
it changes:
print " -file Run Test Cases from this 'xlsm' File. Default = 'San +ityTestCases.xlsx'.\n";
Is there any other way i can make my code 80 characters indented automatically.

Replies are listed 'Best First'.
Re: Perl 80 Chars perl line Rule
by Corion (Pope) on Oct 16, 2012 at 08:36 UTC
    Q:\>perl -nle "print length" "-file Run Test Cases from this 'xlsm' File. Default = 'SanityT +estCases.xlsx'.\n"; 89

    The string itself is longer than 80 chars. It is very hard for a program to break up a string in a sensible and Perl-preserving manner, so you will have to break up these lines manually.

Re: Perl 80 Chars perl line Rule
by MidLifeXis (Monsignor) on Oct 16, 2012 at 12:02 UTC

    Also search for 'outdent' in the perltidy documentation. The string being longer than 80 characters is the main issue, and the behavior of the indentation is controlled by the outdent settings.


Re: Perl 80 Chars perl line Rule
by sundialsvc4 (Abbot) on Oct 16, 2012 at 13:14 UTC

    I wouldn’t hold fast to any sort of “rule,” which definitely to me smacks of the days in which we all used CRTs.   Especially not at the risk of unnecessarily disturbing [large blocks of ...] source-lines that presently work, and of also seriously damaging the revision-tracking capability of the source code control system (SCCS).   If, on a case-by-case basis, it appears that a block of code is inconsistent with its neighbors and therefore genuinely hard-to-read, then I would highlight that block of code and tidy it ... checking in the results (having made no other changes) immediately back into the SCCS, with an appropriate notation, “tidied this.”   (I strongly advocate keeping all such commits separate:   don’t change code and tidy it in the same commit.)

    P.S.:   I’m also not suggesting here that longer source-lines are somehow better.   In fact, “you young turks” should bear in mind that one day your optometrist is going to screw-up your glasses prescription, even to the point of getting the damm things so badly cut that the top half has a different focal-length than the bottom half ... bah!

      The rule is much older than you seem to think. Some of us still remember 80 column IBM punch cards. (Many versions of FORTRAN reserved the last eight of these for "sequence numbers")
        80 col IBM...

        ...and long after that, my first, personally-owned puter: O1 with a (or is memory failing along with my eyes) a 5-inch, 52 column screen.
            Ah, just rolling in the remembered joy of the DD and 80-col upgrades!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://999255]
Approved by Ratazong
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2017-09-20 10:11 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (234 votes). Check out past polls.