Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

need help divining PerlTidy option

by temporal (Pilgrim)
on Oct 25, 2012 at 19:52 UTC ( [id://1000926]=perlquestion: print w/replies, xml ) Need Help??

temporal has asked for the wisdom of the Perl Monks concerning the following question:

I've recently become a PerlTidy fiend since I stumbled upon the hotkey in my IDE that runs it over my working file. Now I not only compulsively save my work, I also compulsively format it. Seriously, my compulsive saving habit is so bad that I have hit Ctrl+S at least twice while composing this post. No, I do not want to save this HTML page, thank you. Hooray for being both paranoid and OCD!

Anyway, optionless PerlTidy doesn't always quite get things formatted to my coding style and occasionally makes some inexplicable decisions. Fortunately, this is rare and PerlTidy and I agree on most aspects of Perl code formatting style.

Which brings me to my reason for posting. I have run into a formatting issue that just drives me bonkers and I want to find the right PerlTidy option(s) to fix it, as my IDE so graciously allows me to specify them in my preferences. A caricature of the code pre- and post-tidying follows:

#! perl -w # my preferred format use strict; my @bar = qw(nagas are snake people); my @zelgo = qw(of course); my @mer = qw(gosh a third nested loop); for my $foo (@bar) { for my $bie (@zelgo) { for my $bletch (@mer) { my $do = bless {}, 'stuff'; $do->DOES(['data', 'data', 'dataaaaaa', 'dataaaaaaaaaaaa' +]) or die "this is a stupidly long die message as you can s +ee from its length\n"; } } }
#! perl -w # after PerlTidy - curious formatting decision use strict; my @bar = qw(nagas are snake people); my @zelgo = qw(of course); my @mer = qw(gosh a third nested loop); for my $foo (@bar) { for my $bie (@zelgo) { for my $bletch (@mer) { my $do = bless {}, 'stuff'; $do->DOES( [ 'data', 'data', 'dataaaaaa', 'dataaaaaaaaaaaa +' ] ) or die "this is a stupidly long die message as you can see from its length\n" ; } } }

I suppose that the difference is not glaring when shown in codeblocks in a forum post. But boy does it drive me crazy what PerlTidy is doing with that long die message. Okay, I can live with PerlTidy wanting to dictate line length, but what fresh hell prevents it from aligning that string on the new line with... at the very least, the innermost enclosing for loop? Ideally, it would be aligned with the or die on the previous line. And what's up with that dangingly (aligned properly, at least!) semi-colon? C'mon, it does not need its own line.

I have examined the PerlTidy docs but there's an awful lot there and I just can't seem to think of how to word my problem so that I can find the proper option for correcting this annoyance.

I'm sure some kind monk has encountered this and has parsed the docs far better than I. Hopefully he or she is willing to share the PerlTidy option(s) necessary to make my code look pretty again? And if not... well, I need to be less OCD anyway.

Replies are listed 'Best First'.
Re: need help divining PerlTidy option
by runrig (Abbot) on Oct 25, 2012 at 21:57 UTC
    Perhaps this:
    -olq, --outdent-long-quotes When -olq is set, lines which is a quoted string longer than the value maximum-line-length will have their indentation removed to make them more readable. This is the default. To prevent such out-denting, use -nolq or --nooutdent-long-lines.
Re: need help divining PerlTidy option
by 2teez (Vicar) on Oct 25, 2012 at 21:26 UTC

    Okay, I can live with PerlTidy wanting to dictate line length, but what fresh hell prevents it from aligning that string on the new line with... at the very least, the innermost enclosing for loop? Ideally, it would be aligned with the or die on the previous line

    The default maximum line length Perltidy uses is 80 columns ( though not cast in stone ), as stated in the Perltidy documentation.
    However, you can change that like so:
    perltidy -l=85 perlscript.pl Please, note the -l=85.
    Given, the OP preferred format, the CLI command work for me to produce the format you want:

    perltidy -b -i=3 -l=90 perlscript.pl
    Please, see EXAMPLES under Perltidy documentation.

    Note, I will advice you don't go beyond between 72 to 82 columns line length except you know what you are doing (ofcourse you do).
    Another option is that, you can reformat manually after using Perltidy or what about that?

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: need help divining PerlTidy option
by Tux (Canon) on Oct 26, 2012 at 09:32 UTC

    Instead of adding arguments to the call, why not write them down in ~/.perltydyrc, where you can add comments and document why you chose the setting and what it does.


    Enjoy, Have FUN! H.Merijn
Re: need help divining PerlTidy option
by temporal (Pilgrim) on Oct 26, 2012 at 08:22 UTC

    Thanks for the replies, guys.

    2teez, I think your solution works only because you extend the line length and then reduce the indentation width. This then allows my example string to fit within the or die line.

    I'd rather have PerlTidy prefer correct indentation alignment over enforcing maximum line length.

    Which is exactly the option that runrig pointed out. The --nooutdent-long-lines option seems to be what I'm looking for. Thanks again, that was driving me crazy =)

    Strange things are afoot at the Circle-K.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-18 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found