numeralize 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/perl
  2. #
  3. # Build a database linking filenames to their numerical representations
  4. # using a keypad for the DialAnMp3 application
  5. #
  6. $mp3dir="/usr/media/mpeg3";
  7. dbmopen(%DIGITS, "/var/lib/asterisk/mp3list", 0644) || die("Unable to open mp3list");;
  8. sub process_dir {
  9. my ($dir) = @_;
  10. my $file;
  11. my $digits;
  12. my @entries;
  13. opendir(DIR, $dir);
  14. @entries = readdir(DIR);
  15. closedir(DIR);
  16. foreach $_ (@entries) {
  17. if (!/^\./) {
  18. $file = "$dir/$_";
  19. if (-d "$file") {
  20. process_dir("$file");
  21. } else {
  22. $digits = $_;
  23. $digits =~ s/[^ \w]+//g;
  24. $digits =~ s/\_/ /g;
  25. $digits =~ tr/[a-z]/[A-Z]/;
  26. $digits =~ tr/[A-C]/2/;
  27. $digits =~ tr/[D-F]/3/;
  28. $digits =~ tr/[G-I]/4/;
  29. $digits =~ tr/[J-L]/5/;
  30. $digits =~ tr/[M-O]/6/;
  31. $digits =~ tr/[P-S]/7/;
  32. $digits =~ tr/[T-V]/8/;
  33. $digits =~ tr/[W-Z]/9/;
  34. $digits =~ s/\s+/ /;
  35. print "File: $file, digits: $digits\n";
  36. $DIGITS{$file} = $digits;
  37. }
  38. }
  39. }
  40. }
  41. process_dir($mp3dir);