Skip to content

Instantly share code, notes, and snippets.

@adamcrussell adamcrussell/ch-1.pl
Last active Oct 6, 2019

Embed
What would you like to do?
Perl Weekly Challenge 028
use strict;
use warnings;
##
# Write a script to check the file content without explicitly reading the content.
# It should accept file name with path as command line argument and
# print "The file content is binary." or else “The file content is ascii.” accordingly.
##
use File::MMagic;
use constant TEXT_TYPE => "The file content is ascii.";
use constant BINARY_TYPE => "The file content is binary.";
my $fm = new File::MMagic();
my $type = $fm->checktype_filename($ARGV[0]);
if($type=~m/text\//){
print TEXT_TYPE . "\n";
}
else{
print BINARY_TYPE . "\n";
}
use strict;
use warnings;
##
# Write a script to display a digital clock.
##
use boolean;
use English;
use DateTime::Set;
use POE q/Component::Schedule/;
$OUTPUT_AUTOFLUSH = true;
sub update_clock{
my $d = DateTime->now();
$d->set_time_zone("America/New_York");
print "\b" x 8;
print "\x1b[93;47m" .
sprintf("%02d", $d->hour) . ":" .
sprintf("%02d", $d->minute) . ":" .
sprintf("%02d", $d->second) .
"\x1b[0m";
}
POE::Session->create(
inline_states => {
_start => sub {
$_[HEAP]{schedule} = POE::Component::Schedule->add(
$_[SESSION], on_tick => DateTime::Set->from_recurrence(
after => DateTime->now,
recurrence => sub{
return $_[0]->truncate(to=>"second")->add(seconds => 1)
},
),
);
},
on_tick => \&update_clock,
},
);
POE::Kernel->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.