App-pltest

 view release on metacpan or  search on metacpan

pltest  view on Meta::CPAN


    >   \'Perl' [
    >     'one',
    >     'liner'
    >   ] undef

Loop over args, printing each with line ending.  And same, SHOUTING:

    pltest -opl '' Perl one liner
    pltest -opl '$_ = uc' Perl one liner

    >   Perl
    >   one
    >   liner
    >   PERL
    >   ONE
    >   LINER

Print up to 3 matching lines, resetting count (and C<$.>) for each file:

    pltest -rP3 '/Perl.*one.*liner/' file*

Count hits in magic statistics hash C<%N(UMBER)>:

    pltest -n '++$NUMBER{$1} while /(Perl|one|liner)/g' file*
    pltest -n '++$N{$1} while /(Perl|one|liner)/g' file*

    >          2: one
    >          7: liner
    >          9: Perl

Though they are sometimes slightly, sometimes quite a bit more complicated,
most Perl one-liners from the internet work, just by omitting C<-e> or C<-E>
(pltest has only one main program, but you can just as well concatenate the C<-e>s
with C<;>).  See L<minor differences|/"Minor Differences with perl -E"> for
exceptions.  There are L<many varied examples|https://metacpan.org/dist/App-pltest/view/pod/examples.pod>.

=head1 DESCRIPTION

I<Don't believe everything you read on SourceForge^H^H^H the internet! --B< >Plato :-y>

Pl follows Perl's philosophy for one-liners: the one variable solely used in
one-liners, C<@F>, is single-lettered.  Because not everyone may like that, pltest
has it both ways.  Everything is aliased both as a word and as a single
letter, including Perl's own C<@F> & C<*ARGV>.

Perl one-liners, and hence pltest, are by nature bilingual.  You must run the
command with its options & arguments, typically from Shell.  By design, Perl
quotes mimic Shell quotes, so here they collide.  As Perl also uses Shell
meta-characters like C<$>, the best solution is to protect Perl-code from the
Shell with single quotes.  That means they can't be used inside.  (An ugly way
around that is C<'\''>, which ends a string, blackslashes a quote and starts
another.)  For literal quotes use C<$q(uote)>.  For quoting use double quotes
or C<q{}>.

I<Shell and Perl, unlike most other languages, don't make you stick your toe
up your nose to get newlines into strings.  So, long "one-liners" are spread
very naturally to legible many-liners.  You get more features on the L<pltest
homepage|https://perl1liner.sourceforge.io/>, like in the veggie-burger menu,
you can toggle many-line display.  In normal text short and long name variants
are initial-bold as C<X(YZ)>.  All examples use the long names, if applicable.
On the homepage those are in the darker blue upper half.  They are repeated with the short variant.  Many examples are followed by their output, indented with C<< > >>.>

=head1 DOCUMENTATION

=head2 Options

Many of perl's options are also available in pltest, sometimes enhanced with extra
functionality.  And the new options complement what perl offers, specifically
oriented towards one liners.

=over

=item C<-0I<[octal]>>

I<perl:> Specify record separator with B<-n>/B<-p> (C<\0>, if no argument).

=item C<-AI<prog>>

Map program over already available C<@A(RGV)> (from command line or previous
B<-A>) or undef.  If program is wrapped in C<{}> use C<grep> instead of
C<map>.  The result becomes the new C<@A(RGV)>.  May be mixed with B<-B>.  The
1st two are equivalent, except that the 1st one isn't limited by Shell line
length limitations.  The third again greps by file size, reading only the Perl
modules less than 1kB:

    pltest -nA '<*.pm>' '...'
    pltest -n '...' *.pm
    pltest -nA '<*.pm>' -A '{ (stat)[7] < 1000 }' '...'

=item C<-a>

I<perl:> Autosplit mode with B<-n>/B<-p> (splits C<$_> into C<@F(IELD)>).

=item C<-bI<prog>>

Run program before reading a new file in B<-n>/B<-p>.

=item C<-BI<prog>>

Add program before main program in same scope.  So you can use it to
initialise C<my> variables.  Whereas, if you define a my variable in the main
program of a B<-n>, B<-p>, B<-P>, B<-o> or B<-O> loop, it's a new variable on
each iteration.  This doesn't do a C<BEGIN> block, unless program is wrapped
in C<{}>.  May be mixed with B<-A>.

=item C<-c>

I<perl:> Check syntax only (runs C<BEGIN> and C<CHECK> blocks).

=item C<-CI<[number/list]>>

I<perl:> Enables the listed Unicode features.

=item C<--colorI<[=when]>>

Colorize (people with impairment have hopefully adapted their system or
browser) some of the output; when can be C<never>, C<always>, or C<auto> (the
default).

=item C<-dI<[:debugger]>>



( run in 1.594 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )