Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion function

Status
Not open for further replies.

job357

Technical User
Sep 16, 2002
106
US
Greetings:
I am new to PERL, and have a little script to fixup, (1) consider, Natives on an island have unusual names for the days and months, (2) add a conversion fuction for the month names, and make the whole thing a library.

This is what I have thus far:

#!/usr/bin/perl -w

@day = qw(ark dip wap sen pop kir);

sub number_to_day_name {
my $num = shift @_; $day[$num];

}

@month = qw(diz pod bod rod sip wax lin sen kun fiz nap dep);

 
/
ghDsu4owrhsdfhjb3fdsvhbfruoabg*
kfggkjngh7bbfdEshbfdsse2gggmgy*
ppqehhbgtyfbnkEz6jfnsfeRwnbfdb*
ghsu4oDwrhsdfhjb3fdsvhbfruoabg*
kfSgkjngh3bbfdshbfddsse2gggmgy*
ppSqehhfbgtyfbnkz6Afnsfewnbfdb*
ghsu4owrhsdfhjb3fdsvX NThb0abg*
kfggkjngh7bbfdshbfdsse2ggxgmgy*
ppqehhfbgtyfbnkz3jfnsfewnbf4bx
/
is the first thing I'd say
,'\/'\@___mybach
 
Paul, I think you need the /x modifier on that.
Would probably also be a good idea to include some comments.
No, seriously, all kidding aside ... :)

The 'translation' idea suggests a hash. You could have a hash like so with the 'native' month names as keys and the 'standard' ones as values
Code:
my %native_months = (
               diz => 'Jan',
               pod => 'Feb',
               bod => 'Mar',
               rod => 'Apr',
               sip => 'May',
               wax => 'Jun',
               lin => 'Jul',
               sen => 'Aug',
               kun => 'Sep',
               fiz => 'Oct',
               nap => 'Nov',
               dep => 'Dec',
);
and a complementary one with the 'standard' names as keys and the 'native' names as values. Then have functions that just return the value from the appropriate hash depending on the key that's passed in, e.g
Code:
sub native2norm {
    # Return standard equivalent of native month 
    my $month = shift;
    $native_months{$month}; 
}
You'd follow the same pattern for days of the week. (Though I note in your example that the natives only seem to have six days in their week, which would make things very problematic. :))

Put these hashes and functions in a library file and 'require' it in your main file.
 
Code:
/
ghDsu4owrhsdfhjb3fdsvhbfruoabg*
kfggkjngh7bbfdEshbfdsse2gggmgy*
ppqehhbgtyfbnkEz6jfnsfeRwnbfdb*
ghsu4oDwrhsdfhjb3fdsvhbfruoabg*
kfSgkjngh3bbfdshbfddsse2gggmgy*
ppSqehhfbgtyfbnkz6Afnsfewnbfdb*
ghsu4owrhsdfhjb3fdsvX NThb0abg*
kfggkjngh7bbfdshbfdsse2ggxgmgy*
ppqehhfbgtyfbnkz3jfnsfewnbf4bx
/
roughly translated from the native tongue of the Islanders is roughly what raklet said

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
mikevh,
This is an excellent selection! Thanks, for the insight! In learning perl, I am often faced with how to tackle a problem, this has put me that much closer to learning PERL.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top