Hi

for many years now many IDEs offer to run code-snippets thru perltidy in a launched sub-process.

But this comes with noticeable delay, because most of the time is lost for startup of perltidy, while Perl::Tidy offers a server mode.

A faster tidying would allow formatting on-the-fly on key-triggers, like when typing return or closing a sub.

Proof

The following code is formatting itself 1,10 and 100 times thru perltidy, and an average run takes less than 0,07 secs

Challenge
Possible technologies
Extra Points

demo code
use v5.12; use warnings; use Perl::Tidy; use Time::HiRes qw/time/; seek DATA,0,0; my $code = join "",<DATA>; #say $code; my $show; my $rc = <<'__CFG__'; --indent-columns=4 --maximum-line-length=80 --variable-maximum-line-length --whitespace-cycle=0 __CFG__ time_it(); sub time_it { for my $times (1,10,100) { my $start=time; run_it() for 1..$times; my $end =time; warn "$times took: ", ($end-$start); } } sub run_it { my $clean; my $stderr; my $error = Perl::Tidy::perltidy ( source => \$code, destination => \$clean, stderr => \$stderr, perltidyrc => \$rc, ); return unless $show; say $code; say '--------'; if ($error) { say 'ERROR'; say $stderr; } else { say $clean; } } __DATA__

1 took: 0.0720160007476807 at c:/tmp/pm/my_tidy.pl line 29, <DATA> lin +e 59. 10 took: 0.643707036972046 at c:/tmp/pm/my_tidy.pl line 29, <DATA> lin +e 59. 100 took: 6.37499022483826 at c:/tmp/pm/my_tidy.pl line 29, <DATA> lin +e 59.

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


In reply to Challenge: Perl::Tidy subprocess for faster formatting by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.