Вы находитесь на странице: 1из 1

#!

/usr/bin/perl
# Another program to analyze a .txt file for firstname
# and grade. Checks to see if the user is legal (age:19)
# or not. Of course, you can always change it.
# Franc
use strict;
use Term::ANSIColor qw/:constants/;
use warnings;
my ($n,$g,$c);
my ($legal,$n_legal);
open F, "age.txt" or die "Could not find file.\n";
while(<F>) {
$c++;
if( ($n,$g) = $_ =~ m/(\w+)\s+(\d+)/) {
if($g >= 19) {
print BOLD, BLUE, "Name: $n\tAge:$g\tStatus: Legal\n", RESET;
$legal++;
}else{
print BOLD, RED, "Name: $n\tAge:$g\tStatus: Not Legal\n", RESET;
$n_legal++;
}
}
}
my $total = $legal + $n_legal;
print "\nFile Stats: \n\n";
print "Total: $total\tLegal: $legal\tNLegal: $n_legal\n";

Вам также может понравиться