Home > Articles > Web Development > Perl

  • Print
  • + Share This
From the author of

How to Use It

Now that the module is built, we need a client to use it. The following is a command-line script that can be used to check if a phone number has any good word mnemonic. This script will either take a phone number as an argument, or it will ask for one if none was given.

    #!/usr/bin/perl -w

    use strict;
    use PhoneToWord;

    my $number = $ARGV[0] || undef;

    unless ($number) {
        print "What is the phone number?\n";
        $number = <STDIN>;
        chomp $number;
    }

    die "No phone number given\n" if !$number;

    print "Checking number: $number\n";

    die "Need a phone number!" unless $number;

    my $ptw_obj = new PhoneToWord qq($number);

    my @three = $ptw_obj->first_three();
    my $four = $ptw_obj->last_four();
    my @all = $ptw_obj->seven();

    print "First three numbers\n";
    print join "\n", @three;
    print "\n";
    print "Second four numbers\n";
    print join "\n", @$four;
    print "\n";
    print "All numbers\n";
    print join "\n", @all;

Here is a sample session using this client:

    # ./get_num.pl   
    What is the phone number?
    344-3549
    Checking number: 344-3549
    First three numbers
    DIG
    EGG
    FIG
    Second four numbers
    FLIX
    All numbers

As you can see, this number leaves us with three choices for a mnemonic: DIG-FLIX, EGG-FLIX, and FIG-FLIX. Much easier to remember than 344-3549! Again, not all phone numbers will have a good mnemonic, but hopefully, the ones you need to remember quickly will!

  • + Share This
  • 🔖 Save To Your Account