понедельник, 22 июня 2015 г.

list pod files ordering by count lines on perl


use strict;
use warnings;
use 5.010;
use Carp;
use English qw(-no_match_vars);
use FindBin '$RealBin';
use Log::Log4perl qw(:easy);
use open qw/:std :utf8/;
use Path::Iterator::Rule;
use IO::All;
use File::Spec::Functions qw(catdir splitdir);
use IPC::Open3;
exit main();
sub main {
my $log_file = $RealBin . "/$0.log";
#Init logging
Log::Log4perl->easy_init(
{ level => $DEBUG,
file => ":utf8>>$log_file",
layout => '%d %p> - %m%n'
}
);
$ENV{PATH} = $ENV{PATH} . q{;C:/Dwimperl/perl/bin};
my $cmd = q{C:/Dwimperl/perl/bin/perldoc.bat -l perldoc};
my @pod_path = splitdir(run_shell($cmd));
my $pod_path = catdir(@pod_path[0 .. $#pod_path - 1]);
my $rule = Path::Iterator::Rule->new;
$rule->name("*.pod");
my $it = $rule->iter($pod_path);
my %pod_files = ();
while (my $file = $it->()) {
my $io = io $file;
my $cnt = scalar $io->getlines;
$pod_files{$file} = $cnt;
}
foreach
my $name (sort { $pod_files{$a} <=> $pod_files{$b} } keys %pod_files)
{
INFO(sprintf "%-8s %s \n", $name, $pod_files{$name});
printf "%-8s %s \n", $name, $pod_files{$name};
}
return 0;
}
sub run_shell {
my ($cmd) = @_;
my $EMPTY = q{};
my ($HIS_IN, $HIS_OUT, $HIS_ERR) = ($EMPTY, $EMPTY, $EMPTY);
my (@outlines, @errlines,@args) = ((), ());
my $childpid = open3($HIS_IN, $HIS_OUT, $HIS_ERR, $cmd, @args);
$ret = print {$HIS_IN} "stuff\n";
close $HIS_IN or croak "unable to close: $HIS_IN $ERRNO";
; # Give end of file to kid.
if ($HIS_OUT) {
@outlines = <$HIS_OUT>; # Read till EOF.
INFO(" STDOUT:\n" . (join "\n", grep { defined; } @outlines));
}
if ($HIS_ERR) {
@errlines = <$HIS_ERR>; # XXX: block potential if massive
ERROR(" STDERR:\n" . (join "\n", grep { defined; } @errlines));
}
close $HIS_OUT or croak "unable to close: $HIS_OUT $ERRNO";
waitpid $childpid, 0;
if ($CHILD_ERROR) {
ERROR("That child exited with wait status of $CHILD_ERROR\n");
}
return @outlines;
}
view raw find_pod.pl hosted with ❤ by GitHub

вторник, 2 июня 2015 г.

script which I made #cpanpr for June


Hi, Neil, I'v done it
use strict;
use warnings;
use 5.010;
use Path::Iterator::Rule;
use File::Slurp;
die "Usage: $0 DIRs" if not @ARGV;
my $rule = Path::Iterator::Rule->new;
$rule->name("*.pm");
my $it = $rule->iter(@ARGV);
while ( my $file = $it->() ) {
say "use strict added to $file";
add_strict_to_file($file);
}
sub add_strict_to_file {
#http://perlmaven.com/splice-to-slice-and-dice-arrays-in-perl
my ($file) = @_;
my @lines = read_file($file);
my @strict = ( 'use strict;', 'use warnings;', '' );
splice @lines, 1, 0, ( join "\n", @strict );
write_file( $file, \@lines );
}
view raw iterate.pl hosted with ❤ by GitHub

concat multiple file with perl iterator


thanks for Gabor
use strict;
use warnings;
use 5.010;
use Path::Iterator::Rule;
use File::Slurp;
die "Usage: $0 DIRs" if not @ARGV;
my $rule = Path::Iterator::Rule->new;
$rule->name("*.sql");
my $big_sql = $ARGV[0] . '/big.sql';
my $it = $rule->iter(@ARGV);
while (my $file = $it->()) {
say "$file was added to $big_sql";
write_file($big_sql, {append => 1}, read_file($file));
}
#thanks for Gabor

понедельник, 1 июня 2015 г.

june pull request

I'v got new task from Neil

01.06.2015, 12:01, "Neil Bowers" <neil@bowers.com>:
> Hi mishin,
>
> Your distribution for June is Memcached-libmemcached:
>     https://metacpan.org/release/Memcached-libmemcached
>
> You should be able to find your dist on github at:
>     https://github.com/timbunce/Memcached-libmemcached
>
> Notes on your distribution:
>  * The distribution has CPANTS warnings - check out its page for details:
>        http://cpants.cpanauthors.org/dist/Memcached-libmemcached
>
> If you really can't work with this dist, get in touch to request
> a new assignment. The list of assignments will be published in 5 days.
>
> When you've completed your assignment, please send me email with subject
> "I'm done". Include your github username in the body of your email.
> You should have done at least one pull request, but you don't have to
> wait for it to be merged when you claim "done", that's up to you.
>
> You can discuss ideas for your PR in a number of places:
>  a. The mailing list
>  b. The #pr-challenge channel on irc.perl.org
> Please get in touch with the author of your assigned dist, to see if there's
> anything they'd like you to do, and to check any ideas you might have.
>
> If you decide to drop out, please let me know, by sending an email "I quit",
> including your github username.
>
> Have fun,
> Neil