### www.perlmonks.org is unreachable
### microsoft.com is unreachable
ping: foo.bar: Name or service not known
### foo.bar is unreachable
return3 is done with pinging
7seconds elapsed during pinging
created file /home/bob/Documents/meditations/template_stuff/translations/28-11-2018-08-18-41.monk.txt
$
####
PING www.google.com(2607:f8b0:400a:803::2004) 56 data bytes
--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 36.669/36.669/36.669/0.000 ms
PING perlmonks.org (66.39.54.27) 56(84) bytes of data.
--- perlmonks.org ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2035ms
PING microsoft.com (40.112.72.205) 56(84) bytes of data.
--- microsoft.com ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2031ms
####
$ ./4.ping3.pl
...
Error utime () on '/home/bob/Documents/meditations/template_stuff/1.monk.tmpl': Permission denied at ./4.ping3.pl line 26.
$ sudo perl 4.ping3.pl
...
### www.google.com is unreachable
### www.translate.yandex.ru is unreachable
### www.bing.com is unreachable
### www.yahoo.com is unreachable
return3 is done with pinging
13seconds elapsed during pinging
####
$ cat 4.ping3.pl
#!/usr/bin/perl -w
use 5.011;
use Path::Tiny;
use POSIX qw(strftime);
# initialization that must precede main data structure
# User: enter a subdirectory you would like to create
# enter a subdirectory of this^^^ for output
my $ts = "template_stuff";
my $output = "translations";
## turning things to Path::Tiny
my $abs = path(__FILE__)->absolute;
my $path1 = Path::Tiny->cwd;
my $path2 = path( $path1, $ts );
say "abs is $abs";
say "path1 is $path1";
say "path2 is $path2";
print "This script will build the above path2. Proceed? (y|n)";
my $prompt = ;
chomp $prompt;
die unless ( $prompt eq "y" );
my $template_file = "1.monk.tmpl";
my $abs_to_template = path( $path2, $template_file )->touchpath;
my $string1 = '<{$symbol}>{$symbol}>';
my $return5 = $abs_to_template->spew_utf8($string1);
say "return5 is $return5";
# script params
my %vars = (
monk_tags => path( $path2, $template_file ),
translations => path( $path2, $output ),
book => 'monastery tags ',
);
my $rvars = \%vars;
my $return1 = write_monk_tags($rvars);
say "return1 is $return1";
my $munge = strftime( "%d-%m-%Y-%H-%M-%S", localtime );
$munge .= ".monk.txt";
# use Path::Tiny to create and write to a text in relevant directory
my $save_file = path( $vars{$output}, $munge )->touchpath;
my $return2 = $save_file->spew_utf8($return1);
say "return2 is $return2";
## ping a few sites and add it to this log; append output
# keep time
my $start = time;
my $return3 = ping_sites($save_file);
say "return3 is $return3";
say time - $start, "seconds elapsed during pinging";
say "created file $save_file";
system("gedit $save_file &");
sub ping_sites {
use 5.011;
use Path::Tiny;
use Net::Ping;
my $outfile = shift;
my $pinger = Net::Ping->new( 'tcp', 3 );
for my $dest (
'www.google.com', 'www.translate.yandex.ru',
'www.bing.com', 'www.yahoo.com'
)
{
$pinger->ping($dest)
or print "### $dest is unreachable\n";
}
$pinger->close;
return "done with pinging";
}
sub write_monk_tags {
use warnings;
use 5.011;
use Text::Template;
my $rvars = shift;
my %vars = %$rvars;
my $body = $vars{"monk_tags"};
my $template = Text::Template->new(
ENCODING => 'utf8',
SOURCE => "$body",
) or die "Couldn't construct template: $!";
my $return = "$vars{\"book\"}\n";
# User: change these quoted values for different order or tags
my @buchstaben = qw/i p c readmore b/;
for my $i (@buchstaben) {
$vars{"symbol"} = $i;
print "How many $i tag pairs would you like?: ";
my $prompt = ;
chomp $prompt;
if ( $prompt lt 1 ) {
$prompt = 0;
}
while ( $prompt gt 0 ) {
my $result = $template->fill_in( HASH => \%vars );
$return = $return . $result;
--$prompt;
}
}
return $return;
}
__END__
$