App-pl

 view release on metacpan or  search on metacpan

pod/examples.pod  view on Meta::CPAN

    pl -n 'if( /^\s*package\s+([^\s;]+)/ ) {
            $d = $1 =~ tr+.+/+r;
        } elsif( /^\s*(?:(?:public|private|protected|abstract|sealed|final)\s+)*(?:class|interface|enum|record)\s+([^\s;]+)/ ) {
            rename $A, "$d/$1.java" or warn "$A -> $d/$1.java: $!\n";
            last;
        }' *.java

=item Delete Matching Files, Except Last One

If you have many files, which sort chronologically by name, and you want to
keep only the last one, it can be quite painful to formulate Shell patterns.
So check on each iteration of the B<-o> loop, if the index C<$ARGIND> (or
C<$I>) is less than the last, before unlinking (deleting).  If you want to test
it first, replace C<unlink> with C<e(cho)>:

    pl -o 'unlink if $ARGIND < $#ARGV' file*
    pl -o 'unlink if $I < $#A' file*

If your resulting list is too long for the Shell, let Perl do it.  Beware that
the Shell has a clever ordering of files, while Perl does it purely lexically!
In the B<-A> code the result is assigned to C<@A(RGV)>, as though it had come



( run in 0.236 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )