fork download
  1. #!/usr/bin/perl
  2. # "Music Live"
  3. my $str = "12 hr 4 min";
  4. my @str1 = split (/\s/, $str);
  5. for($i=0;$i<6;$i++)
  6. {
  7. if($str1[i] eq " ")
  8. {
  9. print "wrong";
  10. }
  11. }
  12. print "\n array ".@str1[0];
  13. print "\n array ".@str1[1];
  14. print "\n array ".@str1[2];
  15. print "\n array ".@str1[3];
  16. print "\n array ".@str1[4];
  17. print "\n array ".@str1[5];
  18. print "\n array ".@str1[6];
  19. my $count = @str1;
  20. print "\n Count ".$count;
  21.  
  22. print "\n str: ".$str."\n";
  23.  
  24. if ( $str1[1] eq "hr")
  25. {
  26. print "Hour";
  27. #if ($str =~ m/[\d]\s[hr][\d\d][min]\s\([partial]\)?/)
  28. #if ($str =~ m/(\d|\d\d)\s[hr]\s+(\d\d)\s+[min]/)
  29. #if ($str =~ m/(\d|\d\d)\s\w\s(\d|\d\d)\s\w/)
  30. if ($str =~ m/(\d|\d\d)\s[hr]\s(\d|\d\d)\s[min]/)
  31. {
  32. print "\nHour data captured";
  33. }
  34. print "\nAfter IF";
  35.  
  36. }elsif($str1[1] eq "min")
  37. {
  38. print "Minute";
  39. }
  40.  
Success #stdin #stdout 0s 4596KB
stdin
Standard input is empty
stdout
 array 12
 array 
 array hr
 array 4
 array min
 array 
 array 
 Count 5
 str: 12  hr 4 min