Advertisement
hackloper775

Edad con Perl

May 30th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.75 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. sub hora {
  4.     my ($diaActual,$mesActual,$anioActual) = ($_[3],$_[4]+1,$_[5]+1900);
  5.     my @inicio =  $ARGV[0] =~ /\S/g;
  6.     my $datos;
  7.     my @edad;
  8.     foreach my $n (@inicio) {
  9.         if ($n =~ /\d/ ) {
  10.             $datos = $datos .+ $n;
  11.         } elsif ($n =~ /\D/) {
  12.             push (@edad,$datos);
  13.             $datos = undef;
  14.         }
  15.     }
  16. push (@edad,$datos);
  17.  
  18. my ($dia,$mes,$anio) =  @edad;
  19.  
  20. if ($mes == $mesActual and $dia > $diaActual) {
  21.     $anioActual = $anioActual - 1;
  22. }
  23.  
  24. if ($mes > $mesActual) {
  25.     $anioActual = $anioActual - 1;
  26. }
  27.  
  28. my $edadActual = $anioActual  -  $anio;
  29.  
  30. print "$edadActual\n";
  31.  
  32. }
  33.  
  34. if ($ARGV[0]) {
  35.     &hora(localtime(time));
  36. } else { print "Uso : perl $0 dia/mes/aƱo\n"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement