Perl Program to calculate age

To calculate the age, we can use following subroutine :

print &age($tmpdob[2],$tmpdob[1],$tmpdob[0]);
sub age {
           # Assuming $birth_month is 0..11
           my ($birth_day, $birth_month, $birth_year) = @_;
           my ($day, $month, $year) = (localtime)[3..5];
          $year += 1900;
          my $age = $year - $birth_year;
          $age-- unless sprintf("%02d%02d", $month, $day)
            >= sprintf("%02d%02d", $birth_month, $birth_day);
          my $mnth=($month>$birth_month)?$month-$birth_month:12+($month-$birth_month);
          return $age."Y/".$mnth."M ";

How to check availability of a folder in perl?

We can check the availability of a folder using Perl as follows :

if(-d "cgi-bin")
          # directory called cgi-bin exists
elsif(-e "cgi-bin")
          # cgi-bin exists but is not a directory
          # nothing called cgi-bin exists

As a note, -e doesn’t distinguish between files and directories. To check if something exists and is a plain file, use -f.