#!/usr/bin/env perl
use strict;
use warnings;
use 5.016;

sub get_battery_stats {
    open my $fh,'<','/sys/class/power_supply/BAT1/uevent';
    my %ret;
    while (my $line=<$fh>) {
        chomp $line;
        my ($name,$value) = $line =~ m{\A POWER_SUPPLY_(.*?) = (.*) \z}x;
        $ret{lc($name)}=$value;
    }
    return \%ret;
}

my $bs=get_battery_stats;
printf "Energy: %.2f%%\n",100*$bs->{energy_now}/$bs->{energy_full};
printf "Time: %.2f / %.2f\n",$bs->{energy_now}/$bs->{power_now},
    $bs->{energy_full}/$bs->{power_now};
